﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using BEGDC.Utility.Castle;
using BEGDC.Utility.DataAccess;
using NHibernate;

namespace BEGDC.PreContract.BLL
{
    public struct SpecialYearQuater
    {
        public static string AfterQuater = "2038";
        public static string AllYear = "2046";
    }
    public class ReportHelper
    {
        public enum ReportType
        {
            ByCAT,
            ByBD,
            ByProv,
            ByProvByCAT,
            ByProvByBD,
            ByCATByBD,
            ByBDByCAT,
            DelayReport,
            RiskProject,
            BlackList,
            BlackListForCAT, //only for get cat dimension for the columns
            ByCAT_Quarterly,
            ByBD_Quarterly,
            ByProv_Quarterly,
            ByProvByCAT_Quarterly,
            ByProvByBD_Quarterly,
            ByCATByBD_Quarterly,
            ByBDByCAT_Quarterly,
            ByProvByCATByDelivery,
            ByProvStatusNo,
            ByCatStatusNo,
            ByPuStatusNo,
            ByProvStatusYes,
            ByCatStatusYes,
            ByPuStatusYes,
            ByCATALL,
            ByBDALL,
            ByProvByCATStatusNo,
            ByClusterStatusYes
        }

        public enum ReportDataType
        {
            Transformed,
            ToBeTransformed,
            Delivered,
            CEWPromised,
        }

        #region public static functions

        public static DataTable GetReportHistory(ReportType rptType)
        {
            IReportHistory rptHistory = (IReportHistory)AppContainer.Instance[Services.CONST_ReportHistory_Service];
            // DataTable dtReport = rptHistory.GetReportHistory("ReportType='" + rptType.ToString().Replace("BD", "PU") + "'");
            DataTable dtReport = rptHistory.GetReportHistory("ReportType='" + rptType + "'");
            return dtReport;

        }
        public static DataTable GetHistReportContent(long rptID)
        {
            IReportHistory rptHistory = (IReportHistory)AppContainer.Instance[Services.CONST_ReportHistory_Service];
            DataTable dtReport = rptHistory.GetReportContentByID(rptID);
            return dtReport;

        }
        public static int GetReportDefaultMonth()
        {
            IReportSearchDefaultMonth irptMonth = (IReportSearchDefaultMonth)AppContainer.Instance[Services.CONST_ReportSearchDefaultMonth_Service];
            DAL.ReportSearchDefaultMonth rptMonth = irptMonth.GetReportSearchDefaultMonth(1);
            if (rptMonth == null)
                return 6;
            return rptMonth.DefaultMonth;
        }

        public static decimal GetExchangeRate()
        {
            IExchangeRate iRate = (IExchangeRate)AppContainer.Instance[Services.CONST_ExchangeRate_Service];
            DAL.ExchangeRate rate = iRate.GetExchangeRate(1);
            if (rate == null)
                return 0;
            return rate.Rate.Value;
        }

        public static bool IsAdmin(long employeeID)
        {
            IUserRole userrole = (IUserRole)AppContainer.Instance[Services.CONST_UserRole_Service];
            return userrole.IsAdmin(employeeID);

        }
        public static bool AllowedDownload(long employeeID)
        {
            IEmployee employee = (IEmployee)AppContainer.Instance[Services.CONST_Employee_Service];
            return employee.AllowedDownload(employeeID);
        }

        public static string GetReportDeadline()
        {
            IDeadline deadlineservice = (IDeadline)AppContainer.Instance[Services.CONST_Deadline_Service];

            DAL.Deadline deadline = deadlineservice.GetDeadline(1);

            if (deadline == null || deadline.DeadlineForData.Value == null)
                return "未设置(Not defined)";
            return deadline.DeadlineForData.Value.ToString("yyyy-MM-dd");
        }

        public static string GetMonthName(int month)
        {
            string monthName = "";
            switch (month)
            {
                case 1:
                    monthName = "Jan";
                    break;
                case 2:
                    monthName = "Feb";
                    break;
                case 3:
                    monthName = "Mar";
                    break;
                case 4:
                    monthName = "Apr";
                    break;
                case 5:
                    monthName = "May";
                    break;
                case 6:
                    monthName = "Jun";
                    break;
                case 7:
                    monthName = "Jul";
                    break;
                case 8:
                    monthName = "Aug";
                    break;
                case 9:
                    monthName = "Sep";
                    break;
                case 10:
                    monthName = "Oct";
                    break;
                case 11:
                    monthName = "Nov";
                    break;
                case 12:
                    monthName = "Dec";
                    break;

            }
            return monthName;

        }
        public static int GetQuaterByMonth(int month)
        {
            int quater = 0;
            switch (month)
            {
                case 1:
                case 2:
                case 3:
                    quater = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quater = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quater = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quater = 4;
                    break;


            }
            return quater;
        }

        public static bool CheckEntityPermission(long employeeID, string asbOrLucent)
        {
            if (asbOrLucent == "")
                asbOrLucent = "2";

            IEmployee employee = (IEmployee)AppContainer.Instance[Services.CONST_Employee_Service];
            if (IsAdmin(employeeID))
                return true;
            return employee.CheckReportPermission(employeeID) && employee.CheckEntityPermission(employeeID, asbOrLucent);
        }


        public static bool IsCloseDateSet()
        {
            ICloseDate closeDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
            return closeDate.IsCloseDateSet();

        }
        public static DataTable SaveHistoryReport(string rptDate, string rptType, string rptContent)
        {
            IReportHistory rptHistory = (IReportHistory)AppContainer.Instance[Services.CONST_ReportHistory_Service];
            DataTable dtTable;

            try
            {
                dtTable = rptHistory.SaveHistoryReport(rptDate, rptType, rptContent);
            }
            catch
            {
                return null;
            }
            return dtTable;
        }
        #endregion

        #region Report Functions

        public static string GetReportByDeliveryDate(long employeeID, ReportType rptType, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values

            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td rowspan='3' class='title_month' colspan='2'>
                                        ByProvByCAT</td>
                                    <td colspan='2' rowspan='2' class='title_month'>
                                        0-19%</td>
                                    <td colspan='2' rowspan='2' class='title_month'>
                                        20-99%</td>
                                    <td colspan='6' class='title_month'>
                                        100%</td>
                                    <td colspan='2' rowspan='2' class='row_total'>
                                        All Total</td>
                                </tr>
                                <tr class='row_title'>
                                    <td colspan='2' class='title_month'>
                                        TOTAL</td>
                                    <td colspan='2' class='title_month'>
                                        Normal</td>
                                    <td colspan='2' class='title_month'>
                                        Loan/Try etc</td>
                                </tr>
                                <tr class='row_title'>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("0-19%");
            arrDate.Add("20-99%");
            arrDate.Add("100% Total");
            arrDate.Add("100% delivery normal");
            arrDate.Add("100% delivery loan/try");
            arrDate.Add("All Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                ////TODO:change title of report
                //if (arrDate[i].ToString() == "All Total")
                //    sb.Append("<td colspan='2' class='row_total'>");
                //else
                //    sb.Append("<td colspan='2' class='title_month'>");

                //sb.Append(arrDate[i].ToString());
                //sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            //sb.Append("</tr>");
            //sb.Append("<tr  class='row_title'><td  class='title_month' colspan='2'>Count</td><td  class='title_month' colspan='2'>Count</td></tr>");
            //sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "All Total")
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate,"", "", 0, 0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }

                if (dtRowDimension.Rows[dimennsionRowIndex][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[dimennsionRowIndex], ref htSubTotal, arrDate, "", "", 0, 0, true);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));
                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }

                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {

                        #region fine the value

                        if (
                                dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                                && dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString()
                               && dtFactValues.Rows[factRowIndex][2].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "All Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], rptType, "2", 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + dblTemp;
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            if (arrDate[arrDateIndex].ToString() == "All Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("</td><td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][4].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], rptType, "2", 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            htSubTotal[arrDateIndex + "-2"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][4].ToString());
                            htTotal[arrDateIndex + "-2"] = Convert.ToDecimal(htTotal[arrDateIndex + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][4].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                        #endregion
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "All Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                        }
                    }

                    #endregion


                }
                sb.Append("</tr>");
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetReportByDeliveryDate(long employeeID, ReportType rptType, int adjust,out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values

            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0, adjust);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td rowspan='3' class='title_month' colspan='2'>
                                        ByProvByCAT</td>
                                    <td colspan='2' rowspan='2' class='title_month'>
                                        0-19%</td>
                                    <td colspan='2' rowspan='2' class='title_month'>
                                        20-99%</td>
                                    <td colspan='6' class='title_month'>
                                        100%</td>
                                    <td colspan='2' rowspan='2' class='row_total'>
                                        All Total</td>
                                </tr>
                                <tr class='row_title'>
                                    <td colspan='2' class='title_month'>
                                        TOTAL</td>
                                    <td colspan='2' class='title_month'>
                                        Normal</td>
                                    <td colspan='2' class='title_month'>
                                        Loan/Try etc</td>
                                </tr>
                                <tr class='row_title'>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("0-19%");
            arrDate.Add("20-99%");
            arrDate.Add("100% Total");
            arrDate.Add("100% delivery normal");
            arrDate.Add("100% delivery loan/try");
            arrDate.Add("All Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                ////TODO:change title of report
                //if (arrDate[i].ToString() == "All Total")
                //    sb.Append("<td colspan='2' class='row_total'>");
                //else
                //    sb.Append("<td colspan='2' class='title_month'>");

                //sb.Append(arrDate[i].ToString());
                //sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            //sb.Append("</tr>");
            //sb.Append("<tr  class='row_title'><td  class='title_month' colspan='2'>Count</td><td  class='title_month' colspan='2'>Count</td></tr>");
            //sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "All Total")
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate,"", "", 0, 0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }

                if (dtRowDimension.Rows[dimennsionRowIndex][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[dimennsionRowIndex], ref htSubTotal, arrDate, "", "", 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));
                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }

                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {

                        #region fine the value

                        if (
                                dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                                && dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString()
                               && dtFactValues.Rows[factRowIndex][2].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "All Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], rptType, "2", 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + dblTemp;
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            if (arrDate[arrDateIndex].ToString() == "All Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("</td><td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][4].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], rptType, "2", 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            htSubTotal[arrDateIndex + "-2"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][4].ToString());
                            htTotal[arrDateIndex + "-2"] = Convert.ToDecimal(htTotal[arrDateIndex + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][4].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                        #endregion
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "All Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                        }
                    }

                    #endregion


                }
                sb.Append("</tr>");
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetReportByProvStatusNo(long employeeID, ReportType reportType, DateTime currentDate, int contractType, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, 0, 0, currentDate, contractType);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td class='title_month'>
                                        ByProv</td>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total",
                                        "0-19%<br>Delivered",
                                        "20-99%<br>Delivered",
                                        "100%<br>Delivered"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            bool bFound;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(reportType, ref htTotal, arrDate, "", "", 0, 0, true, currentDate, contractType);
                    sb.Append(strTemp);
                    continue;
                }
                sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>");
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {

                        #region fine the value

                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                            && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], reportType, "2", 0, 0, ReportDataType.CEWPromised, currentDate, contractType));
                            sb.Append(dblTemp.ToString());
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                        #endregion
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td>");
                        }
                    }

                    #endregion
                }
                sb.Append("</tr>");
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-20
        public static string GetReportByProvStatusNo2Dim(long employeeID, ReportType reportType, DateTime currentDate, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, 0, 0, adjust, currentDate, -1);
            DataTable dtFactValues = dtSet.Tables[0];

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();//++
            StringBuilder sbTableExcel = new StringBuilder();

            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                            <tr class='row_title'>
                                                <td class='title_month' colspan='2'>ByProv</td> ";

            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total",
                                        "0-19%<br>Delivered",
                                        "20-99%<br>Delivered",
                                        "100%<br>Delivered"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total
            Hashtable htSubTotal = new Hashtable(); //For save subtotal

            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-1", 0);
            }

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());

            sb.Length = 0;
            int m = 0;
            string strTemp = "";
            string strRptTitle;
            bool bFound;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel; ;

            #endregion

            for (int dimRowIndex = 0; dimRowIndex < dtRowDimension.Rows.Count; dimRowIndex++)
            {
                if (dtRowDimension.Rows[dimRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(reportType, ref htTotal, arrDate, "", "", 0, 0, true, currentDate, 0,adjust);
                    sbTable.Append(strTemp); 
                    sbTableExcel.Append(strTemp);
                    
                    continue;
                }
                if (dtRowDimension.Rows[dimRowIndex][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp); 
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sbExcel.ToString());

                    strTemp = GetSubTotal(reportType, dtRowDimension.Rows[dimRowIndex], ref htSubTotal, arrDate, true, currentDate, 0,adjust);
                    sbTable.Append(strTemp); 
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }

                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[dimRowIndex][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[dimRowIndex][3] + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimRowIndex][3] + "</td>");
                }

                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (dtRowDimension.Rows[dimRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                             && dtRowDimension.Rows[dimRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString()
                             && arrDate[arrDateIndex].ToString() == dtFactValues.Rows[factRowIndex][2].ToString())
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "Total")
                                sb.Append("<td class='row_total'>");
                            else
                                sb.Append("<td>");

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimRowIndex], dtFactValues.Rows[factRowIndex], reportType, "2", 0, 0, ReportDataType.CEWPromised, currentDate, 0,adjust));
                            sb.Append(dblTemp.ToString());
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][3].ToString());
                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td>");
                        }
                    }
                }
                sb.Append("</tr>");

                sbExcel = sb;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //changed, yu liang 2010-5-28
        public static string GetReportByCatStatusNo(long employeeID, ReportType reportType, DateTime currentDate, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, 0, 0,adjust, currentDate, 0);
            DataTable dtFactValues = dtSet.Tables[0];

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td class='title_month'>
                                        ByCat</td>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total",
                                        "0-19%<br>Delivered",
                                        "20-99%<br>Delivered",
                                        "100%<br>Delivered"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            bool bFound;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(reportType, ref htTotal, arrDate, "", "", 0, 0, true, currentDate, 0,adjust);
                    sb.Append(strTemp);
                    continue;
                }
                sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>");
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {

                        #region fine the value

                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                            && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], reportType, "2", 0, 0, ReportDataType.CEWPromised, currentDate, 0,adjust));
                            sb.Append(dblTemp.ToString());
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                        #endregion
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td>");
                        }
                    }

                    #endregion
                }
                sb.Append("</tr>");
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //changed, yuliang 2010-5-28
        public static string GetReportByPuStatusNo(long employeeID, ReportType reportType, DateTime currentDate, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, 0, 0, adjust,currentDate, 0);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td class='title_month'>
                                        ByPU</td>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total",
                                         "0-19%<br>Delivered",
                                        "20-99%<br>Delivered",
                                        "100%<br>Delivered"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total
            Hashtable htSubTotal = new Hashtable();
            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);

            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            bool bFound;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(reportType, ref htTotal, arrDate, "", "", 0, 0, true, currentDate, 0, adjust);
                    sb.Append(strTemp);
                    continue;
                }
                if (dtRowDimension.Rows[dimennsionRowIndex][2] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][3] == DBNull.Value)
                {
                    strTemp = GetSubTotal(reportType, dtRowDimension.Rows[dimennsionRowIndex], ref htSubTotal, arrDate, true, currentDate, 0, adjust);
                    sb.Append(strTemp);
                    continue;
                }
                sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {

                        #region fine the value

                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                            && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], reportType, "2", 0, 0, ReportDataType.CEWPromised, currentDate, 0, adjust));
                            sb.Append(dblTemp.ToString());
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][2].ToString());
                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][2].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                        #endregion
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td>");
                        }
                    }

                    #endregion
                }
                sb.Append("</tr>");
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //changed, yuliang 2010-5-28
        public static string GetReportByProvByCatStatusNo(long employeeID, ReportType reportType, DateTime currentDate, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, 0, 0, adjust,currentDate, 0);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td class='title_month'  colspan='2'>
                                        ByProvByCat</td>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total",
                                         "0-19%<br>Delivered",
                                        "20-99%<br>Delivered",
                                        "100%<br>Delivered"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total
            Hashtable htSubTotal = new Hashtable();
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-1", 0);

            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());

            sb.Length = 0;
            int m = 0;
            string strTemp = "";
            string strRptTitle;
            bool bFound;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(reportType, ref htTotal, arrDate, "", "", 0, 0, true, currentDate, 0,adjust);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    continue;
                }
                if (dtRowDimension.Rows[dimennsionRowIndex][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sbExcel.ToString());

                    strTemp = GetSubTotal(reportType, dtRowDimension.Rows[dimennsionRowIndex], ref htSubTotal, arrDate, true, currentDate, 0,adjust);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }

                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");
                }

                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    bFound = false;

                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                             && dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString()
                             && dtFactValues.Rows[factRowIndex][2].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[arrDateIndex].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append(GetLink(dtRowDimension.Rows[dimennsionRowIndex], dtFactValues.Rows[factRowIndex], reportType, "2", 0, 0, ReportDataType.CEWPromised, currentDate, 0,adjust));
                            sb.Append(dblTemp.ToString());
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][3].ToString());
                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[factRowIndex][3].ToString());
                            sb.Append("</a>");
                            sb.Append("</td>");
                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        if (arrDate[arrDateIndex].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td>");
                        }
                    }
                }
                sb.Append("</tr>");

                sbExcel = sb;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //changed, yu liang 2010-5-28
        public static string GetReportByCatStatusYes(long employeeID, ReportType reportType, int year, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, year, 0,adjust, null, -1);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                        <tr class='row_title'>
                                        <td class='title_month'>" + (reportType == ReportType.ByCatStatusYes ? "By Cat" : "By Prov") + @"</td><td class='title_month'>Data</td>
                                        ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total


            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);
            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            string tmp = "<td>金额</td><td>1-1</td><td>1-2</td><td>1-3</td><td>1-4</td><td>1-5</td><td class='row_total'>1-6</td></tr>";
            tmp += "<tr class='row_body'><td>%</td><td>2-1</td><td>2-2</td><td>2-3</td><td>2-4</td><td>2-5</td><td class='row_total'>2-6</td></tr>";
            tmp += "<tr class='row_body'><td>数量</td><td>3-1</td><td>3-2</td><td>3-3</td><td>3-4</td><td>3-5</td><td class='row_total'>3-6</td></tr>";

            string tmpStr = string.Empty;
            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                tmpStr = tmp;
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal2(reportType, ref htTotal, year, adjust);
                    sb.Append(strTemp);
                    continue;
                }

                sb.Append("<tr class='row_body'><td rowspan='3'>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>");

                for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                {

                    if (dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString())
                    {
                        dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                        string tmpDbl = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dblTemp + "</a>";
                        string count = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dtFactValues.Rows[factRowIndex][3].ToString() + "</a>";
                        string percent = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + GetPercent(dtFactValues.Rows[factRowIndex][3].ToString(), dtFactValues.Rows[factRowIndex][0].ToString(), dtFactValues) + "</a>";
                        if (dtFactValues.Rows[factRowIndex][1].ToString() == "<1Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-1", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-1", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-1", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "1-3Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-2", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-2", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-2", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "3-6Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-3", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-3", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-3", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "6-12Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-4", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-4", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-4", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == ">1Year")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-5", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-5", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-5", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "Total")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-6", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-6", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-6", count);
                        }
                    }
                }
                for (int i = 1; i < 7; i++)
                {
                    tmpStr = tmpStr.Replace(i + "-", "-").Replace("-" + i, "-");
                }
                //替换现有的行中的值
                sb.Append(tmpStr);
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    //得到汇总
                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                                && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            decimal tmpDbl = 0M;
                            decimal.TryParse(dtFactValues.Rows[factRowIndex][2].ToString(), out tmpDbl);
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + tmpDbl;
                            htTotal[arrDateIndex + "-2"] = Convert.ToInt32(htTotal[arrDateIndex + "-2"]) + Convert.ToInt32(dtFactValues.Rows[factRowIndex][3].ToString());

                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                }
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-23
        public static string GetReportByClusterStatusYes(long employeeID, ReportType reportType, int year, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, year, 0, adjust, null, -1);
            DataTable dtFactValues = dtSet.Tables[0];


            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                        <tr class='row_title'>
                                        <td class='title_month'>By Cluster</td><td class='title_month'>Data</td>
                                        ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total


            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);
            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            string tmp = "<td>金额</td><td>1-1</td><td>1-2</td><td>1-3</td><td>1-4</td><td>1-5</td><td class='row_total'>1-6</td></tr>";
            tmp += "<tr class='row_body'><td>%</td><td>2-1</td><td>2-2</td><td>2-3</td><td>2-4</td><td>2-5</td><td class='row_total'>2-6</td></tr>";
            tmp += "<tr class='row_body'><td>数量</td><td>3-1</td><td>3-2</td><td>3-3</td><td>3-4</td><td>3-5</td><td class='row_total'>3-6</td></tr>";

            string tmpStr = string.Empty;
            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                tmpStr = tmp;
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal2(reportType, ref htTotal, year, adjust);
                    sb.Append(strTemp);
                    continue;
                }

                sb.Append("<tr class='row_body'><td rowspan='3'>" + dtRowDimension.Rows[dimennsionRowIndex][1] + "</td>");

                for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                {

                    if (dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString())
                    {
                        dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                        string tmpDbl = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dblTemp + "</a>";
                        string count = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dtFactValues.Rows[factRowIndex][3].ToString() + "</a>";
                        string percent = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + GetPercent(dtFactValues.Rows[factRowIndex][3].ToString(), dtFactValues.Rows[factRowIndex][0].ToString(), dtFactValues) + "</a>";
                        if (dtFactValues.Rows[factRowIndex][1].ToString() == "<1Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-1", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-1", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-1", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "1-3Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-2", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-2", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-2", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "3-6Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-3", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-3", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-3", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "6-12Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-4", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-4", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-4", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == ">1Year")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-5", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-5", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-5", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "Total")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-6", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-6", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-6", count);
                        }
                    }
                }
                for (int i = 1; i < 7; i++)
                {
                    tmpStr = tmpStr.Replace(i + "-", "-").Replace("-" + i, "-");
                }
                //替换现有的行中的值
                sb.Append(tmpStr);
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    //得到汇总
                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][0].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                                && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            decimal tmpDbl = 0M;
                            decimal.TryParse(dtFactValues.Rows[factRowIndex][2].ToString(), out tmpDbl);
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + tmpDbl;
                            htTotal[arrDateIndex + "-2"] = Convert.ToInt32(htTotal[arrDateIndex + "-2"]) + Convert.ToInt32(dtFactValues.Rows[factRowIndex][3].ToString());

                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                }
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-22
        public static string GetReportByProvStatusYes(long employeeID, ReportType reportType, int year, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, year, 0, adjust,null, -1);
            DataTable dtFactValues = dtSet.Tables[0];

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                     <tr class='row_title'>
                                         <td class='title_month'>By Prov</td>
                                         <td class='title_month'>Data</td>";

            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total
            Hashtable htSubTotal = new Hashtable(); //yl +

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                htSubTotal.Add(i + "-1", 0);//yl+
                htSubTotal.Add(i + "-2", 0);//yl+
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);
            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            int m = 0;
            sb.Length = 0;
            string strTemp = "";
            string strRptTitle;
            //double dblTemp = new double();
            decimal dblTemp;

            #region Get Report title

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            string tmp = "<td>金额</td><td>1-1</td><td>1-2</td><td>1-3</td><td>1-4</td><td>1-5</td><td class='row_total'>1-6</td></tr>";
            tmp += "<tr class='row_body'><td>%</td><td>2-1</td><td>2-2</td><td>2-3</td><td>2-4</td><td>2-5</td><td class='row_total'>2-6</td></tr>";
            tmp += "<tr class='row_body'><td>数量</td><td>3-1</td><td>3-2</td><td>3-3</td><td>3-4</td><td>3-5</td><td class='row_total'>3-6</td></tr>";

            string tmpStr = string.Empty;
            for (int dimRowIndex = 0; dimRowIndex < dtRowDimension.Rows.Count; dimRowIndex++)
            {
                tmpStr = tmp;
                if (dtRowDimension.Rows[dimRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal2(reportType, ref htTotal, year, adjust);
                    sb.Append(strTemp);

                    continue;
                }

                //if (dtRowDimension.Rows[dimRowIndex][2] == DBNull.Value)
                //{
                //    strTemp = string.Format(strTemp, m * 3);
                //    sbTable.Append(strTemp); sbTableExcel.Append(strTemp);
                //    sbTable.Append(sb.ToString()); sbTableExcel.Append(sb.ToString());
                //    strTemp = GetTotal(reportType, ref htTotal, year, contractType);
                //    sb.Append(strTemp);

                //    sb.Length = 0;
                //    m = 0;
                //    continue;

                //    //strTemp = string.Format(strTemp, m * 3);
                //    //sbTable.Append(strTemp); sbTableExcel.Append(strTemp);
                //    //sbTable.Append(sb.ToString()); sbTableExcel.Append(sb.ToString());
                //    //strTemp = GetSubTotal(reportType, dtRowDimension.Rows[dimRowIndex], ref htSubTotal, arrDate, true, null, contractType);
                //    //sbTable.Append(strTemp); sbTableExcel.Append(strTemp.Replace("<br>", ""));
                //    //sb.Length = 0;
                //    //m = 0;
                //    //continue;
                //}

//                m++;
//                if (m == 1)
//                {
//                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[dimRowIndex][1] + "</td>";
//                    sb.Append("<td>" + dtRowDimension.Rows[dimRowIndex][3] + "</td>");
//                }
//                else
//                {
//                    sb.Append(String.Format( @"<tr class='row_body'>
//                                    <td rowspan='3'>{0}</td>
//                                    <td>金额</td><td>1-1</td><td>1-2</td><td>1-3</td><td>1-4</td><td>1-5</td><td class='row_total'>1-6</td>
//                                </tr>
//                                <tr class='row_body'>
//                                    <td>%</td><td>2-1</td><td>2-2</td><td>2-3</td><td>2-4</td><td>2-5</td><td class='row_total'>2-6</td>
//                                </tr>
//                                <tr class='row_body'>
//                                    <td>数量</td><td>3-1</td><td>3-2</td><td>3-3</td><td>3-4</td><td>3-5</td><td class='row_total'>3-6</td>
//                                </tr>",dtRowDimension.Rows[dimRowIndex][3]));

//                    //sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[dimRowIndex][3] + "</td>");
//                }

                //
                sb.Append("<tr class='row_body'><td rowspan='3'>" + dtRowDimension.Rows[dimRowIndex][3] + "</td>");

                for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                {
                    if (dtRowDimension.Rows[dimRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString())
                    {
                        dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][3].ToString());
                        string tmpDbl = GetLink2(dtRowDimension.Rows[dimRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][2].ToString(), false) + dblTemp + "</a>";
                        string count = GetLink2(dtRowDimension.Rows[dimRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][2].ToString(), false) + dtFactValues.Rows[factRowIndex][4].ToString() + "</a>";
                        string percent = GetLink2(dtRowDimension.Rows[dimRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][2].ToString(), false) + GetPercentForProvStatusYes(dtFactValues.Rows[factRowIndex][4].ToString(), dtFactValues.Rows[factRowIndex][1].ToString(), dtFactValues) + "</a>";
                        if (dtFactValues.Rows[factRowIndex][2].ToString() == "<1Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-1", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-1", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-1", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][2].ToString() == "1-3Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-2", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-2", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-2", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][2].ToString() == "3-6Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-3", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-3", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-3", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][2].ToString() == "6-12Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-4", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-4", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-4", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][2].ToString() == ">1Year")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-5", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-5", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-5", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][2].ToString() == "Total")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-6", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-6", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-6", count);
                        }
                    }
                }
                for (int i = 1; i < 7; i++)
                {
                    tmpStr = tmpStr.Replace(i + "-", "-").Replace("-" + i, "-");
                }
                //替换现有的行中的值
                sb.Append(tmpStr);
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    //得到汇总
                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (dtRowDimension.Rows[dimRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][1].ToString()
                         && arrDate[arrDateIndex].ToString() == dtFactValues.Rows[factRowIndex][2].ToString())
                        {
                            decimal tmpDbl = 0M;
                            decimal.TryParse(dtFactValues.Rows[factRowIndex][3].ToString(), out tmpDbl);
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + tmpDbl;
                            htTotal[arrDateIndex + "-2"] = Convert.ToInt32(htTotal[arrDateIndex + "-2"]) + Convert.ToInt32(dtFactValues.Rows[factRowIndex][4].ToString());

                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                }
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-28
        public static string GetReportByPuStatusYes(long employeeID, ReportType reportType, int year, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, reportType, year);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, reportType, "", 0, year, 0,adjust, null, -1);
            DataTable dtFactValues = dtSet.Tables[0];

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();

            StringBuilder sbTableExcel = new StringBuilder();
            const string tableTile = @"<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'>
                                <tr class='row_title'>
                                    <td class='title_month'>
                                        ByPu</td><td class='title_month'>Data</td>
                            ";
            string tbForPage = tableTile;
            string tbForExcel = tableTile;

            ArrayList arrDate = new ArrayList
                                    {
                                        "<1Month",
                                        "1-3Month",
                                        "3-6Month",
                                        "6-12Month",
                                        ">1Year",
                                        "Total"
                                    };

            Hashtable htTotal = new Hashtable();    //For save total
            Hashtable htSubTotal = new Hashtable();

            for (int i = 0; i < arrDate.Count; i++)
            {
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);

            }
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>" + arrDate[i] + "</td>");
                else
                    sb.Append("<td  class='title_month'>" + arrDate[i] + "</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());

            sb.Length = 0;
            string strTemp;
            string strRptTitle;
            //double dblTemp = new double();
            decimal dblTemp;

            strRptTitle = GetReportTitle(reportType, "", "", "");
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            string tmp = "<td>金额</td><td>1-1</td><td>1-2</td><td>1-3</td><td>1-4</td><td>1-5</td><td class='row_total'>1-6</td></tr>";
            tmp += "<tr class='row_body'><td>%</td><td>2-1</td><td>2-2</td><td>2-3</td><td>2-4</td><td>2-5</td><td class='row_total'>2-6</td></tr>";
            tmp += "<tr class='row_body'><td>数量</td><td>3-1</td><td>3-2</td><td>3-3</td><td>3-4</td><td>3-5</td><td class='row_total'>3-6</td></tr>";

            string tmpStr = string.Empty;
            for (int dimennsionRowIndex = 0; dimennsionRowIndex < dtRowDimension.Rows.Count; dimennsionRowIndex++)
            {
                tmpStr = tmp;
                if (dtRowDimension.Rows[dimennsionRowIndex][0] == DBNull.Value && dtRowDimension.Rows[dimennsionRowIndex][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal2(reportType, ref htTotal, year, adjust);
                    sb.Append(strTemp);
                    continue;
                }
                if (dtRowDimension.Rows[dimennsionRowIndex][2] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetSubTotal2(reportType, dtRowDimension.Rows[dimennsionRowIndex], ref htSubTotal, year, adjust);
                    sb.Append(strTemp);
                    continue;
                }
                sb.Append("<tr class='row_body'><td rowspan='3'>" + dtRowDimension.Rows[dimennsionRowIndex][3] + "</td>");


                for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                {

                    if (dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][0].ToString())
                    {
                        dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[factRowIndex][2].ToString());
                        string tmpDbl = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dblTemp + "</a>";
                        string count = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + dtFactValues.Rows[factRowIndex][3] + "</a>";
                        string percent = GetLink2(dtRowDimension.Rows[dimennsionRowIndex], reportType, year, adjust, dtFactValues.Rows[factRowIndex][1].ToString(), false) + GetPercent(dtFactValues.Rows[factRowIndex][3].ToString(), dtFactValues.Rows[factRowIndex][0].ToString(), dtFactValues) + "</a>";
                        if (dtFactValues.Rows[factRowIndex][1].ToString() == "<1Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-1", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-1", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-1", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "1-3Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-2", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-2", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-2", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "3-6Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-3", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-3", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-3", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "6-12Month")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-4", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-4", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-4", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == ">1Year")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-5", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-5", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-5", count);
                        }
                        else if (dtFactValues.Rows[factRowIndex][1].ToString() == "Total")
                        {
                            //money
                            tmpStr = tmpStr.Replace("1-6", tmpDbl);
                            //%
                            tmpStr = tmpStr.Replace("2-6", percent);
                            //Count
                            tmpStr = tmpStr.Replace("3-6", count);
                        }
                    }
                }
                for (int i = 1; i < 7; i++)
                {
                    tmpStr = tmpStr.Replace(i + "-", "-").Replace("-" + i, "-");
                }
                //替换现有的行中的值
                sb.Append(tmpStr);
                for (int arrDateIndex = 0; arrDateIndex < arrDate.Count; arrDateIndex++)
                {
                    //得到汇总
                    for (int factRowIndex = 0; factRowIndex < dtFactValues.Rows.Count; factRowIndex++)
                    {
                        if (
                               dtRowDimension.Rows[dimennsionRowIndex][2].ToString() == dtFactValues.Rows[factRowIndex][0].ToString()
                                && dtFactValues.Rows[factRowIndex][1].ToString() == arrDate[arrDateIndex].ToString()
                            )
                        {
                            decimal tmpDbl = 0M;
                            decimal.TryParse(dtFactValues.Rows[factRowIndex][2].ToString(), out tmpDbl);
                            htTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htTotal[arrDateIndex + "-1"]) + tmpDbl;
                            htTotal[arrDateIndex + "-2"] = Convert.ToInt32(htTotal[arrDateIndex + "-2"]) + Convert.ToInt32(dtFactValues.Rows[factRowIndex][3].ToString());

                            htSubTotal[arrDateIndex + "-1"] = Convert.ToDecimal(htSubTotal[arrDateIndex + "-1"]) + tmpDbl;
                            htSubTotal[arrDateIndex + "-2"] = Convert.ToInt32(htSubTotal[arrDateIndex + "-2"]) + Convert.ToInt32(dtFactValues.Rows[factRowIndex][3].ToString());

                            dtFactValues.Rows.RemoveAt(factRowIndex);
                            factRowIndex--;
                            break;
                        }
                    }
                }
            }

            tbForPage = tbForPage + sbTable + sb + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + sb + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetReportHTML2DimByDate(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            #region Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, 0, 0);
            DataTable dtColDimension = dtSet.Tables[0];
            DataTable dtFactValues = dtSet.Tables[1];
            #endregion

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForPage = tbForPage.Replace("_Quarterly", "");
            tbForExcel += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForExcel = tbForExcel.Replace("_Quarterly", "");

            int n = 0;
            Hashtable ht = new Hashtable();
            ArrayList arrDate = new ArrayList();
            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total
            string currYear = "";
            string lastYear = "";

            #region fill date head in ArrayList

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][2] == DBNull.Value)
                {
                    if (dtColDimension.Rows[i][1] == DBNull.Value && dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Year
                        ht.Add(n, "Y");
                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);


                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        if ((currYear == "") && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AllYear) && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AfterQuater))
                        {
                            //with Transformed data
                            currYear = dtColDimension.Rows[i][0].ToString();
                            sb.Append("<td colspan='3' class='title_year'>");
                            htSubTotal.Add(n + "-0", 0);
                            htTotal.Add(n + "-0", 0);
                        }
                        else
                        {
                            sb.Append("<td colspan='2' class='title_year'>");
                        }
                        if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AllYear)
                        {
                            sb.Append("All Total");
                        }
                        else if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AfterQuater)
                        {
                            ICloseDate iCloseDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
                            DataTable dt = iCloseDate.GetCloseDateByDate(DateTime.Now);
                            sb.Append("After Q" + dt.Rows[0][DAL.CloseDate.CONST_Quarter] + " ");
                        }
                        else
                        {
                            sb.Append(dtColDimension.Rows[i][0] + " Total");
                        }

                        sb.Append("</td>");

                        lastYear = dtColDimension.Rows[i][0].ToString();
                        n++;

                    }
                    else if (dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Quater
                        ht.Add(n, "Q");

                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        sb.Append("<td colspan='2'  class='title_quater'>");
                        sb.Append(dtColDimension.Rows[i][0].ToString());
                        sb.Append(" Q");
                        sb.Append(dtColDimension.Rows[i][1].ToString());
                        sb.Append("</td>");
                        n++;

                    }

                }
                else
                {
                    //Month
                    ht.Add(n, "M");

                    htSubTotal.Add(n + "-1", 0);
                    htSubTotal.Add(n + "-2", 0);
                    htTotal.Add(n + "-1", 0);
                    htTotal.Add(n + "-2", 0);

                    arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);
                    sb.Append("<td colspan='2'  class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][0].ToString());
                    sb.Append(" ");
                    sb.Append(GetMonthName(Convert.ToInt32(dtColDimension.Rows[i][2].ToString())));
                    sb.Append("</td>");
                    n++;

                }
            }

            sb.Append("</tr>");
            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (ht[i].ToString() == "Y")
                {
                    if ((arrDate[i].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                        sb.Append("<td class='title_year'>Have Transformed</td>");

                    sb.Append("<td class='title_year'>To Be Transformed</td><td  class='title_year'>Delivered</td>");
                }
                else if (ht[i].ToString() == "Q")
                    sb.Append("<td class='title_quater'>To Be Transformed</td><td class='title_quater'>Delivered</td>");

                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion



            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, currYear, lastYear, asbOrLucent);
            //tbForPage = strRptTitle + tbForPage;
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, asbOrLucent, currYear, 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType,ref htTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion


                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sbExcel.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, asbOrLucent, currYear, 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType,dtRowDimension.Rows[i], ref htSubTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;
                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && MapValue(arrDate[j].ToString(), dtFactValues.Rows[k][2], dtFactValues.Rows[k][3], dtFactValues.Rows[k][4])
                            )
                        {
                            bFound = true;
                            if (ht[j].ToString() == "Y")
                            {

                                if (dtFactValues.Rows[k][2].ToString() == currYear)
                                {
                                    sb.Append("<td>");
                                    //sbExcel.Append("<td>");

                                    dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][5].ToString());

                                    //Check transformed Count
                                    if (Convert.ToInt32(dtFactValues.Rows[k][8].ToString()) != 0)
                                    {
                                        sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Transformed));

                                        sb.Append(dblTemp.ToString());
                                        //sbExcel.Append(dblTemp.ToString());

                                        htSubTotal[j + "-0"] = Convert.ToDecimal(htSubTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        htTotal[j + "-0"] = Convert.ToDecimal(htTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        sb.Append("</a>");
                                    }
                                    else
                                    {
                                        sb.Append("-");
                                        //sbExcel.Append("-");
                                    }

                                    //sb.Append(dtFactValues.Rows[k][5].ToString());

                                    sb.Append("</td>");
                                    //sbExcel.Append("</td>");
                                }

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());


                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else if (ht[j].ToString() == "Q")
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());
                                sb.Append("</a>");
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }
                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }

                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (ht[j].ToString() == "Y")
                        {
                            if ((arrDate[j].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                            {
                                //Have transformed
                                sb.Append("<td>-</td>");
                                //sbExcel.Append("<td>-</td>");
                            }
                            //     sb.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                            //     sbExcel.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                        }
                        // else if (ht[j].ToString() == "Q")
                        // {
                        //     sb.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //     sbExcel.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //}
                        // else
                        // {
                        //     sb.Append("<td>-</td><td>-</td>");
                        //     sbExcel.Append("<td>-</td><td>-</td>");
                        // }
                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");  

                    }
                    #endregion

                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");
                //sbTable.Append(sb.ToString());
                //sb.Length = 0;
                sbExcel = sb;

            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetReportHTML2DimByDate(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int adjust,out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            #region Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, 0, 0, adjust);
            DataTable dtColDimension = dtSet.Tables[0];
            DataTable dtFactValues = dtSet.Tables[1];
            #endregion

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForPage = tbForPage.Replace("_Quarterly", "");
            tbForExcel += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForExcel = tbForExcel.Replace("_Quarterly", "");

            int n = 0;
            Hashtable ht = new Hashtable();
            ArrayList arrDate = new ArrayList();
            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total
            string currYear = "";
            string lastYear = "";

            #region fill date head in ArrayList

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][2] == DBNull.Value)
                {
                    if (dtColDimension.Rows[i][1] == DBNull.Value && dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Year
                        ht.Add(n, "Y");
                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);


                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        if ((currYear == "") && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AllYear) && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AfterQuater))
                        {
                            //with Transformed data
                            currYear = dtColDimension.Rows[i][0].ToString();
                            sb.Append("<td colspan='3' class='title_year'>");
                            htSubTotal.Add(n + "-0", 0);
                            htTotal.Add(n + "-0", 0);
                        }
                        else
                        {
                            sb.Append("<td colspan='2' class='title_year'>");
                        }
                        if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AllYear)
                        {
                            sb.Append("All Total");
                        }
                        else if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AfterQuater)
                        {
                            ICloseDate iCloseDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
                            DataTable dt = iCloseDate.GetCloseDateByDate(DateTime.Now);
                            sb.Append("After Q" + dt.Rows[0][DAL.CloseDate.CONST_Quarter] + " ");
                        }
                        else
                        {
                            sb.Append(dtColDimension.Rows[i][0] + " Total");
                        }

                        sb.Append("</td>");

                        lastYear = dtColDimension.Rows[i][0].ToString();
                        n++;

                    }
                    else if (dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Quater
                        ht.Add(n, "Q");

                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        sb.Append("<td colspan='2'  class='title_quater'>");
                        sb.Append(dtColDimension.Rows[i][0].ToString());
                        sb.Append(" Q");
                        sb.Append(dtColDimension.Rows[i][1].ToString());
                        sb.Append("</td>");
                        n++;

                    }

                }
                else
                {
                    //Month
                    ht.Add(n, "M");

                    htSubTotal.Add(n + "-1", 0);
                    htSubTotal.Add(n + "-2", 0);
                    htTotal.Add(n + "-1", 0);
                    htTotal.Add(n + "-2", 0);

                    arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);
                    sb.Append("<td colspan='2'  class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][0].ToString());
                    sb.Append(" ");
                    sb.Append(GetMonthName(Convert.ToInt32(dtColDimension.Rows[i][2].ToString())));
                    sb.Append("</td>");
                    n++;

                }
            }

            sb.Append("</tr>");
            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (ht[i].ToString() == "Y")
                {
                    if ((arrDate[i].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                        sb.Append("<td class='title_year'>Have Transformed</td>");

                    sb.Append("<td class='title_year'>To Be Transformed</td><td  class='title_year'>Delivered</td>");
                }
                else if (ht[i].ToString() == "Q")
                    sb.Append("<td class='title_quater'>To Be Transformed</td><td class='title_quater'>Delivered</td>");

                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, currYear, lastYear, asbOrLucent);
            //tbForPage = strRptTitle + tbForPage;
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, asbOrLucent, currYear, 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType,ref htTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion

                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sbExcel.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, asbOrLucent, currYear, 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType,dtRowDimension.Rows[i], ref htSubTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion

                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;
                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && MapValue(arrDate[j].ToString(), dtFactValues.Rows[k][2], dtFactValues.Rows[k][3], dtFactValues.Rows[k][4])
                            )
                        {
                            bFound = true;
                            if (ht[j].ToString() == "Y")
                            {

                                if (dtFactValues.Rows[k][2].ToString() == currYear)
                                {
                                    sb.Append("<td>");
                                    //sbExcel.Append("<td>");

                                    dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][5].ToString());

                                    //Check transformed Count
                                    if (Convert.ToInt32(dtFactValues.Rows[k][8].ToString()) != 0)
                                    {
                                        sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Transformed,adjust));

                                        sb.Append(dblTemp.ToString());
                                        //sbExcel.Append(dblTemp.ToString());

                                        htSubTotal[j + "-0"] = Convert.ToDecimal(htSubTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        htTotal[j + "-0"] = Convert.ToDecimal(htTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        sb.Append("</a>");
                                    }
                                    else
                                    {
                                        sb.Append("-");
                                        //sbExcel.Append("-");
                                    }

                                    //sb.Append(dtFactValues.Rows[k][5].ToString());

                                    sb.Append("</td>");
                                    //sbExcel.Append("</td>");
                                }

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());


                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else if (ht[j].ToString() == "Q")
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());
                                sb.Append("</a>");
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered,adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }
                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }

                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (ht[j].ToString() == "Y")
                        {
                            if ((arrDate[j].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                            {
                                //Have transformed
                                sb.Append("<td>-</td>");
                                //sbExcel.Append("<td>-</td>");
                            }
                            //     sb.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                            //     sbExcel.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                        }
                        // else if (ht[j].ToString() == "Q")
                        // {
                        //     sb.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //     sbExcel.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //}
                        // else
                        // {
                        //     sb.Append("<td>-</td><td>-</td>");
                        //     sbExcel.Append("<td>-</td><td>-</td>");
                        // }
                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");  

                    }
                    #endregion

                    #endregion
                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");
                //sbTable.Append(sb.ToString());
                //sb.Length = 0;
                sbExcel = sb;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetReportHTML1DimByDate(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;

            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, 0, 0);
            DataTable dtColDimension = dtSet.Tables[0];
            DataTable dtFactValues = dtSet.Tables[1];
            //DataTable dtAggregatedValues = dtSet.Tables[2];

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();


            tbForPage = "<table border='0' width='300px' cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForPage = tbForPage.Replace("_Quarterly", "");
            tbForExcel += "<td rowspan='2'colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForExcel = tbForExcel.Replace("_Quarterly", "");

            int n = 0;
            Hashtable ht = new Hashtable();
            ArrayList arrDate = new ArrayList();
            //Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            string currYear = "";
            string lastYear = "";

            #region fill date head in ArrayList

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][2] == DBNull.Value)
                {
                    if (dtColDimension.Rows[i][1] == DBNull.Value && dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Year
                        ht.Add(n, "Y");
                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);


                        //htSubTotal.Add(n.ToString() + "-1", 0);
                        //htSubTotal.Add(n.ToString() + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        if ((currYear == "") && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AllYear) && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AfterQuater))
                        {
                            //with Transformed data
                            currYear = dtColDimension.Rows[i][0].ToString();
                            sb.Append("<td colspan='3' class='title_year'>");
                            //htSubTotal.Add(n.ToString() + "-0", 0);
                            htTotal.Add(n + "-0", 0);
                        }
                        else
                        {
                            sb.Append("<td colspan='2' class='title_year'>");
                        }
                        if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AllYear)
                        {
                            sb.Append("All Total");
                        }
                        else if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AfterQuater)
                        {
                            ICloseDate iCloseDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
                            DataTable dt = iCloseDate.GetCloseDateByDate(DateTime.Now);

                            sb.Append("After Q" + dt.Rows[0][DAL.CloseDate.CONST_Quarter] + " ");
                        }
                        else
                        {
                            sb.Append(dtColDimension.Rows[i][0] + " Total");
                        }

                        sb.Append("</td>");
                        lastYear = dtColDimension.Rows[i][0].ToString();
                        n++;


                    }
                    else if (dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Quater
                        ht.Add(n, "Q");

                        //htSubTotal.Add(n.ToString() + "-1", 0);
                        //htSubTotal.Add(n.ToString() + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        sb.Append("<td colspan='2'  class='title_quater'>");
                        sb.Append(dtColDimension.Rows[i][0].ToString());
                        sb.Append(" Q");
                        sb.Append(dtColDimension.Rows[i][1].ToString());
                        sb.Append("</td>");
                        n++;

                    }

                }
                else
                {
                    //Month
                    ht.Add(n, "M");

                    //htSubTotal.Add(n.ToString() + "-1", 0);
                    //htSubTotal.Add(n.ToString() + "-2", 0);
                    htTotal.Add(n + "-1", 0);
                    htTotal.Add(n + "-2", 0);

                    arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);
                    sb.Append("<td colspan='2'  class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][0].ToString());
                    sb.Append(" ");
                    sb.Append(GetMonthName(Convert.ToInt32(dtColDimension.Rows[i][2].ToString())));

                    sb.Append("</td>");
                    n++;

                }
            }

            sb.Append("</tr>");
            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (ht[i].ToString() == "Y")
                {
                    if ((arrDate[i].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                        sb.Append("<td class='title_year'>Have Transformed</td>");

                    sb.Append("<td class='title_year'>To Be Transformed</td><td  class='title_year'>Delivered</td>");
                }
                else if (ht[i].ToString() == "Q")
                    sb.Append("<td class='title_quater'>To Be Transformed</td><td class='title_quater'>Delivered</td>");

                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion




            sb.Length = 0;
            sbExcel.Length = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();


            #region Get Report title
            strRptTitle = GetReportTitle(rptType, currYear, lastYear, asbOrLucent);
            //tbForPage = strRptTitle + tbForPage;
            rptTitle = strRptTitle;

            tbForExcel = strRptTitle + tbForExcel;
            #endregion



            strTemp = "";
            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value)// && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, asbOrLucent, currYear, 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType,ref htTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp);
                    continue;
                }
                #endregion

                sb.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1] + "</td>");
                //sbExcel.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1].ToString() + "</td>");

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;
                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString()
                                && MapValue(arrDate[j].ToString(), dtFactValues.Rows[k][2], dtFactValues.Rows[k][3], dtFactValues.Rows[k][4])
                            )
                        {
                            bFound = true;
                            if (ht[j].ToString() == "Y")
                            {

                                if (dtFactValues.Rows[k][2].ToString() == currYear)
                                {
                                    sb.Append("<td>");
                                    //sbExcel.Append("<td>");

                                    dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][5].ToString());

                                    //Check transformed Count
                                    if (Convert.ToInt32(dtFactValues.Rows[k][8].ToString()) != 0)
                                    {
                                        sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Transformed));

                                        sb.Append(dblTemp.ToString());
                                        //sbExcel.Append(dblTemp.ToString());

                                        //htSubTotal[j.ToString() + "-0"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-0"]) + dblTemp;
                                        htTotal[j + "-0"] = Convert.ToDecimal(htTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        sb.Append("</a>");
                                    }
                                    else
                                    {
                                        sb.Append("-");
                                        //sbExcel.Append("-");
                                    }


                                    sb.Append("</td>");
                                    //sbExcel.Append("</td>");
                                }

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());


                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else if (ht[j].ToString() == "Q")
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</a>");
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }

                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (ht[j].ToString() == "Y")
                        {
                            if ((arrDate[j].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                            {
                                //Have transformed
                                sb.Append("<td>-</td>");
                                //sbExcel.Append("<td>-</td>");
                            }
                        }

                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");

                    }
                    #endregion

                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                sbTable.Append(sb.ToString());
                //sbTableExcel.Append(sbExcel.ToString());
                sbTableExcel.Append(sb.ToString());

                sb.Length = 0;
                sbExcel.Length = 0;


            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetReportHTML1DimByDate(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth,int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;

            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, 0, 0, adjust);
            DataTable dtColDimension = dtSet.Tables[0];
            DataTable dtFactValues = dtSet.Tables[1];
            //DataTable dtAggregatedValues = dtSet.Tables[2];

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();


            tbForPage = "<table border='0' width='300px' cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForPage = tbForPage.Replace("_Quarterly", "");
            tbForExcel += "<td rowspan='2'colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForExcel = tbForExcel.Replace("_Quarterly", "");

            int n = 0;
            Hashtable ht = new Hashtable();
            ArrayList arrDate = new ArrayList();
            //Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            string currYear = "";
            string lastYear = "";

            #region fill date head in ArrayList

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][2] == DBNull.Value)
                {
                    if (dtColDimension.Rows[i][1] == DBNull.Value && dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Year
                        ht.Add(n, "Y");
                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);


                        //htSubTotal.Add(n.ToString() + "-1", 0);
                        //htSubTotal.Add(n.ToString() + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        if ((currYear == "") && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AllYear) && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AfterQuater))
                        {
                            //with Transformed data
                            currYear = dtColDimension.Rows[i][0].ToString();
                            sb.Append("<td colspan='3' class='title_year'>");
                            //htSubTotal.Add(n.ToString() + "-0", 0);
                            htTotal.Add(n + "-0", 0);
                        }
                        else
                        {
                            sb.Append("<td colspan='2' class='title_year'>");
                        }
                        if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AllYear)
                        {
                            sb.Append("All Total");
                        }
                        else if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AfterQuater)
                        {
                            ICloseDate iCloseDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
                            DataTable dt = iCloseDate.GetCloseDateByDate(DateTime.Now);

                            sb.Append("After Q" + dt.Rows[0][DAL.CloseDate.CONST_Quarter] + " ");
                        }
                        else
                        {
                            sb.Append(dtColDimension.Rows[i][0] + " Total");
                        }

                        sb.Append("</td>");
                        lastYear = dtColDimension.Rows[i][0].ToString();
                        n++;


                    }
                    else if (dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Quater
                        ht.Add(n, "Q");

                        //htSubTotal.Add(n.ToString() + "-1", 0);
                        //htSubTotal.Add(n.ToString() + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        sb.Append("<td colspan='2'  class='title_quater'>");
                        sb.Append(dtColDimension.Rows[i][0].ToString());
                        sb.Append(" Q");
                        sb.Append(dtColDimension.Rows[i][1].ToString());
                        sb.Append("</td>");
                        n++;

                    }

                }
                else
                {
                    //Month
                    ht.Add(n, "M");

                    //htSubTotal.Add(n.ToString() + "-1", 0);
                    //htSubTotal.Add(n.ToString() + "-2", 0);
                    htTotal.Add(n + "-1", 0);
                    htTotal.Add(n + "-2", 0);

                    arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);
                    sb.Append("<td colspan='2'  class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][0].ToString());
                    sb.Append(" ");
                    sb.Append(GetMonthName(Convert.ToInt32(dtColDimension.Rows[i][2].ToString())));

                    sb.Append("</td>");
                    n++;

                }
            }

            sb.Append("</tr>");
            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (ht[i].ToString() == "Y")
                {
                    if ((arrDate[i].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                        sb.Append("<td class='title_year'>Have Transformed</td>");

                    sb.Append("<td class='title_year'>To Be Transformed</td><td  class='title_year'>Delivered</td>");
                }
                else if (ht[i].ToString() == "Q")
                    sb.Append("<td class='title_quater'>To Be Transformed</td><td class='title_quater'>Delivered</td>");

                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();


            #region Get Report title
            strRptTitle = GetReportTitle(rptType, currYear, lastYear, asbOrLucent);
            //tbForPage = strRptTitle + tbForPage;
            rptTitle = strRptTitle;

            tbForExcel = strRptTitle + tbForExcel;
            #endregion

            strTemp = "";
            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value)// && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, asbOrLucent, currYear, 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType,ref htTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp);
                    continue;
                }
                #endregion

                sb.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1] + "</td>");
                //sbExcel.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1].ToString() + "</td>");

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;
                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString()
                                && MapValue(arrDate[j].ToString(), dtFactValues.Rows[k][2], dtFactValues.Rows[k][3], dtFactValues.Rows[k][4])
                            )
                        {
                            bFound = true;
                            if (ht[j].ToString() == "Y")
                            {

                                if (dtFactValues.Rows[k][2].ToString() == currYear)
                                {
                                    sb.Append("<td>");
                                    //sbExcel.Append("<td>");

                                    dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][5].ToString());

                                    //Check transformed Count
                                    if (Convert.ToInt32(dtFactValues.Rows[k][8].ToString()) != 0)
                                    {
                                        sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Transformed, adjust));

                                        sb.Append(dblTemp.ToString());
                                        //sbExcel.Append(dblTemp.ToString());

                                        //htSubTotal[j.ToString() + "-0"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-0"]) + dblTemp;
                                        htTotal[j + "-0"] = Convert.ToDecimal(htTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        sb.Append("</a>");
                                    }
                                    else
                                    {
                                        sb.Append("-");
                                        //sbExcel.Append("-");
                                    }


                                    sb.Append("</td>");
                                    //sbExcel.Append("</td>");
                                }

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());


                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else if (ht[j].ToString() == "Q")
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-1"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-1"]) + dblTemp;
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }


                                sb.Append("</a>");
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered, adjust));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    //htSubTotal[j.ToString() + "-2"] = System.Convert.ToDecimal(htSubTotal[j.ToString() + "-2"]) + dblTemp;
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }

                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (ht[j].ToString() == "Y")
                        {
                            if ((arrDate[j].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                            {
                                //Have transformed
                                sb.Append("<td>-</td>");
                                //sbExcel.Append("<td>-</td>");
                            }
                        }

                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");

                    }
                    #endregion

                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                sbTable.Append(sb.ToString());
                //sbTableExcel.Append(sbExcel.ToString());
                sbTableExcel.Append(sb.ToString());

                sb.Length = 0;
                sbExcel.Length = 0;


            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetReportHTML3DimByDate(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int adjust, out string err, out string excelHTML, out string rptTitle)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            #region Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, 0, 0, adjust);
            DataTable dtColDimension = dtSet.Tables[0];
            DataTable dtFactValues = dtSet.Tables[1];
            #endregion

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForPage = tbForPage.Replace("_Quarterly", "");
            tbForExcel += "<td rowspan='2' colspan='2'>" + rptType.ToString().Replace("BD", "PU") + "</td>";
            tbForExcel = tbForExcel.Replace("_Quarterly", "");

            int n = 0;
            Hashtable ht = new Hashtable();
            ArrayList arrDate = new ArrayList();
            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total
            string currYear = "";
            string lastYear = "";

            #region fill date head in ArrayList

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                #region Year & Quarter
                if (dtColDimension.Rows[i][2] == DBNull.Value)
                {
                    #region Year
                    if (dtColDimension.Rows[i][1] == DBNull.Value && dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Year
                        ht.Add(n, "Y");
                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        if ((currYear == "") && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AllYear) && (dtColDimension.Rows[i][0].ToString() != SpecialYearQuater.AfterQuater))
                        {
                            //with Transformed data
                            currYear = dtColDimension.Rows[i][0].ToString();
                            sb.Append("<td colspan='3' class='title_year'>");
                            htSubTotal.Add(n + "-0", 0);
                            htTotal.Add(n + "-0", 0);
                        }
                        else
                        {
                            sb.Append("<td colspan='2' class='title_year'>");
                        }
                        if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AllYear)
                        {
                            sb.Append("All Total");
                        }
                        else if (dtColDimension.Rows[i][0].ToString() == SpecialYearQuater.AfterQuater)
                        {
                            ICloseDate iCloseDate = (ICloseDate)AppContainer.Instance[Services.CONST_CloseDate_Service];
                            DataTable dt = iCloseDate.GetCloseDateByDate(DateTime.Now);
                            sb.Append("After Q" + dt.Rows[0][DAL.CloseDate.CONST_Quarter] + " ");
                        }
                        else
                        {
                            sb.Append(dtColDimension.Rows[i][0] + " Total");
                        }

                        sb.Append("</td>");

                        lastYear = dtColDimension.Rows[i][0].ToString();
                        n++;

                    }
                    #endregion Year
                    else if (dtColDimension.Rows[i][0] != DBNull.Value)
                    {
                        //Quater
                        ht.Add(n, "Q");

                        htSubTotal.Add(n + "-1", 0);
                        htSubTotal.Add(n + "-2", 0);
                        htTotal.Add(n + "-1", 0);
                        htTotal.Add(n + "-2", 0);

                        arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);

                        sb.Append("<td colspan='2' class='title_quater'>");
                        sb.Append(dtColDimension.Rows[i][0].ToString());
                        sb.Append(" Q");
                        sb.Append(dtColDimension.Rows[i][1].ToString());
                        sb.Append("</td>");
                        n++;

                    }

                }
                #endregion Year & Quarter
                #region Month
                else
                {
                    //Month
                    ht.Add(n, "M");

                    htSubTotal.Add(n + "-1", 0);
                    htSubTotal.Add(n + "-2", 0);
                    htTotal.Add(n + "-1", 0);
                    htTotal.Add(n + "-2", 0);

                    arrDate.Add("Y" + dtColDimension.Rows[i][0] + "Q" + dtColDimension.Rows[i][1] + "M" + dtColDimension.Rows[i][2]);
                    sb.Append("<td colspan='2'  class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][0].ToString());
                    sb.Append(" ");
                    sb.Append(GetMonthName(Convert.ToInt32(dtColDimension.Rows[i][2].ToString())));
                    sb.Append("</td>");
                    n++;

                }
                #endregion Month
            }

            sb.Append("</tr>");
            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (ht[i].ToString() == "Y")
                {
                    if ((arrDate[i].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                        sb.Append("<td class='title_year'>Have Transformed</td>");

                    sb.Append("<td class='title_year'>To Be Transformed</td><td  class='title_year'>Delivered</td>");
                }
                else if (ht[i].ToString() == "Q")
                    sb.Append("<td class='title_quater'>To Be Transformed</td><td class='title_quater'>Delivered</td>");

                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion fill date head in ArrayList

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, currYear, lastYear, asbOrLucent);
            //tbForPage = strRptTitle + tbForPage;
            rptTitle = strRptTitle;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion

            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, asbOrLucent, currYear, 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType,ref htTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion

                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    sbTableExcel.Append(sbExcel.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, asbOrLucent, currYear, 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType,dtRowDimension.Rows[i], ref htSubTotal, arrDate,asbOrLucent,currYear,0,0,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion

                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;
                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && MapValue(arrDate[j].ToString(), dtFactValues.Rows[k][2], dtFactValues.Rows[k][3], dtFactValues.Rows[k][4])
                            )
                        {
                            bFound = true;
                            if (ht[j].ToString() == "Y")
                            {

                                if (dtFactValues.Rows[k][2].ToString() == currYear)
                                {
                                    sb.Append("<td>");
                                    //sbExcel.Append("<td>");

                                    dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][5].ToString());

                                    //Check transformed Count
                                    if (Convert.ToInt32(dtFactValues.Rows[k][8].ToString()) != 0)
                                    {
                                        sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Transformed));

                                        sb.Append(dblTemp.ToString());
                                        //sbExcel.Append(dblTemp.ToString());

                                        htSubTotal[j + "-0"] = Convert.ToDecimal(htSubTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        htTotal[j + "-0"] = Convert.ToDecimal(htTotal[j + "-0"]) + Convert.ToDecimal(dtFactValues.Rows[k][5].ToString());
                                        sb.Append("</a>");
                                    }
                                    else
                                    {
                                        sb.Append("-");
                                        //sbExcel.Append("-");
                                    }

                                    //sb.Append(dtFactValues.Rows[k][5].ToString());

                                    sb.Append("</td>");
                                    //sbExcel.Append("</td>");
                                }

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());


                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");

                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else if (ht[j].ToString() == "Q")
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());

                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][6].ToString());
                                //Check to be transformed Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][9].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.ToBeTransformed));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][6].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }

                                //sb.Append(dtFactValues.Rows[k][6].ToString());
                                sb.Append("</a>");
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");

                                dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][7].ToString());
                                //Check delivered Count
                                if (Convert.ToInt32(dtFactValues.Rows[k][10].ToString()) != 0)
                                {
                                    sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.Delivered));
                                    sb.Append(dblTemp.ToString());
                                    //sbExcel.Append(dblTemp.ToString());
                                    htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][7].ToString());
                                    sb.Append("</a>");
                                }
                                else
                                {
                                    sb.Append("-");
                                    //sbExcel.Append("-");
                                }
                                //sb.Append(dtFactValues.Rows[k][7].ToString());

                                sb.Append("</td>");
                                //sbExcel.Append("</td>");
                            }

                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (ht[j].ToString() == "Y")
                        {
                            if ((arrDate[j].ToString().IndexOf('Y' + currYear) >= 0) && (currYear != string.Empty))
                            {
                                //Have transformed
                                sb.Append("<td>-</td>");
                                //sbExcel.Append("<td>-</td>");
                            }
                            //     sb.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                            //     sbExcel.Append("<td class='title_year'>-</td><td class='title_year'>-</td>");
                        }
                        // else if (ht[j].ToString() == "Q")
                        // {
                        //     sb.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //     sbExcel.Append("<td class='title_quater'>-</td><td class='title_quater'>-</td>");
                        //}
                        // else
                        // {
                        //     sb.Append("<td>-</td><td>-</td>");
                        //     sbExcel.Append("<td>-</td><td>-</td>");
                        // }
                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");  

                    }
                    #endregion

                    #endregion
                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");
                //sbTable.Append(sb.ToString());
                //sb.Length = 0;
                sbExcel = sb;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetDelayReportHTML(long employeeID, ReportType rptType, out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values

            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0);
            DataTable dtFactValues = dtSet.Tables[0];


            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("Not Due");
            arrDate.Add("0-3 Month");
            arrDate.Add("3-6 Month");
            arrDate.Add("6-12 Month");
            arrDate.Add("12-24 Month");
            arrDate.Add(">24 Month");
            arrDate.Add("Total");
            arrDate.Add("All Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td colspan='2' class='row_total'>");
                else
                    sb.Append("<td colspan='2' class='title_month'>");

                sb.Append(arrDate[i].ToString());
                sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate,"", "", 0, 0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion


                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    //sbTableExcel.Append(sbExcel.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, "", "", 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType,dtRowDimension.Rows[i], ref htSubTotal, arrDate,"","",0,0,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && dtFactValues.Rows[k][2].ToString() == arrDate[j].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                                //sbExcel.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //Check to be transformed Count
                            //if (Convert.ToInt32(dtFactValues.Rows[k][5].ToString()) != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + dblTemp;
                            htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    //sbExcel.Append("-");
                            //}

                            sb.Append("</a>");
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                                //sbExcel.Append("</td><td class='row_total'>");                                

                            }
                            else
                            {
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");       
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][4].ToString());
                            //Check Delivered Count
                            //if (Convert.ToInt32(dtFactValues.Rows[k][6].ToString()) != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                            htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    //sbExcel.Append("-");
                            //}
                            //sb.Append(dtFactValues.Rows[k][7].ToString());

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (arrDate[j].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                            //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                            //sbExcel.Append("<td>-</td><td>-</td>");
                        }
                    }
                    #endregion
                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                //sbTable.Append(sb.ToString());
                //sb.Length = 0;

            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetDelayReportHTML(long employeeID, ReportType rptType, int adjust, out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values

            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0, adjust);
            DataTable dtFactValues = dtSet.Tables[0];


            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("Not Due");
            arrDate.Add("0-3 Month");
            arrDate.Add("3-6 Month");
            arrDate.Add("6-12 Month");
            arrDate.Add("12-24 Month");
            arrDate.Add(">24 Month");
            arrDate.Add("Total");
            arrDate.Add("All Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td colspan='2' class='row_total'>");
                else
                    sb.Append("<td colspan='2' class='title_month'>");

                sb.Append(arrDate[i].ToString());
                sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate,"", "", 0, 0,false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion


                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    //sbTableExcel.Append(sbExcel.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, "", "", 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType,dtRowDimension.Rows[i], ref htSubTotal, arrDate,"","",0,0,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && dtFactValues.Rows[k][2].ToString() == arrDate[j].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                                //sbExcel.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                            }
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //Check to be transformed Count
                            //if (Convert.ToInt32(dtFactValues.Rows[k][5].ToString()) != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + dblTemp;
                            htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    //sbExcel.Append("-");
                            //}

                            sb.Append("</a>");
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                                //sbExcel.Append("</td><td class='row_total'>");                                

                            }
                            else
                            {
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");       
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][4].ToString());
                            //Check Delivered Count
                            //if (Convert.ToInt32(dtFactValues.Rows[k][6].ToString()) != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                            htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    //sbExcel.Append("-");
                            //}
                            //sb.Append(dtFactValues.Rows[k][7].ToString());

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (arrDate[j].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                            //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                            //sbExcel.Append("<td>-</td><td>-</td>");
                        }
                    }
                    #endregion
                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                //sbTable.Append(sb.ToString());
                //sb.Length = 0;

            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetRiskReportHTML(long employeeID, ReportType rptType, int year, int quater, out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, year, quater);
            DataTable dtFactValues = dtSet.Tables[0];


            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("Secure");
            arrDate.Add("Risk");
            arrDate.Add("Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td colspan='2' class='row_total'>");
                else
                    sb.Append("<td colspan='2' class='title_month'>");

                sb.Append(arrDate[i].ToString());
                sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>To Be Transformed</td><td class='row_total'>Delivered</td>");
                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", year, quater, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate, "","", year, quater, false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion


                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    //sbTableExcel.Append(sbExcel.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, "", "", year, quater, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate,"","",year,quater,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && dtFactValues.Rows[k][2].ToString() == arrDate[j].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                                //sbExcel.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //check to be transformed count
                            if (Convert.ToInt32(dtFactValues.Rows[k][5].ToString()) != 0)
                            {
                                sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", year, quater, ReportDataType.ToBeTransformed));
                                sb.Append(dblTemp.ToString());
                                //sbExcel.Append(dblTemp.ToString());
                                htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                                htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                                sb.Append("</a>");
                            }
                            else
                            {
                                sb.Append("-");
                                //sbExcel.Append("-");
                            }

                            sb.Append("</a>");
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                                //sbExcel.Append("</td><td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][4].ToString());
                            //Check Delivered Count
                            if (Convert.ToInt32(dtFactValues.Rows[k][6].ToString()) != 0)
                            {
                                sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", year, quater, ReportDataType.Delivered));
                                sb.Append(dblTemp.ToString());
                                //sbExcel.Append(dblTemp.ToString());
                                htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                                htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                                sb.Append("</a>");
                            }
                            else
                            {
                                sb.Append("-");
                                //sbExcel.Append("-");
                            }
                            //sb.Append(dtFactValues.Rows[k][7].ToString());

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (arrDate[j].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                            //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                            //sbExcel.Append("<td>-</td><td>-</td>");
                        }
                    }
                    #endregion
                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                //sbTable.Append(sb.ToString());
                //sb.Length = 0;

            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetRiskReportHTML(long employeeID, ReportType rptType, int year, int quater,int adjust, out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;
            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, year, quater, adjust);
            DataTable dtFactValues = dtSet.Tables[0];


            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>ByProvByCAT</td>";


            ArrayList arrDate = new ArrayList();
            #region build column arraylist
            arrDate.Add("Secure");
            arrDate.Add("Risk");
            arrDate.Add("Total");
            #endregion

            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region fill  head in Array
            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td colspan='2' class='row_total'>");
                else
                    sb.Append("<td colspan='2' class='title_month'>");

                sb.Append(arrDate[i].ToString());
                sb.Append("</td>");
                htSubTotal.Add(i + "-1", 0);
                htSubTotal.Add(i + "-2", 0);
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);

            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < arrDate.Count; i++)
            {
                if (arrDate[i].ToString() == "Total")
                    sb.Append("<td  class='row_total'>To Be Transformed</td><td class='row_total'>Delivered</td>");
                else
                    sb.Append("<td  class='title_month'>To Be Transformed</td><td class='title_month'>Delivered</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            int m = 0;
            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrDate, "", "", year, quater, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrDate, "","", year, quater, false);
                    sbTableExcel.Append(strTemp);
                    continue;

                }
                #endregion


                #region if ROLLUP line for first Level, close rowspan and output sub total by Month, Quater and Year

                if (dtRowDimension.Rows[i][2] == DBNull.Value)
                {
                    strTemp = string.Format(strTemp, m);
                    sbTable.Append(strTemp);
                    sbTableExcel.Append(strTemp);

                    sbTable.Append(sb.ToString());
                    //sbTableExcel.Append(sbExcel.ToString());
                    sbTableExcel.Append(sb.ToString());

                    strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate, "", "", year, quater, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetSubTotal(rptType, dtRowDimension.Rows[i], ref htSubTotal, arrDate,"","",year,quater,false);
                    sbTableExcel.Append(strTemp.Replace("<br>", ""));

                    //insert subtotal line.
                    sb.Length = 0;
                    sbExcel.Length = 0;
                    m = 0;
                    continue;
                }


                #endregion


                m++;
                if (m == 1)
                {
                    strTemp = "<tr class='row_body'><td rowspan='{0}'>" + dtRowDimension.Rows[i][1] + "</td>";
                    sb.Append("<td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3] + "</td>");
                    //sbExcel.Append("<tr class='row_body'><td>" + dtRowDimension.Rows[i][3].ToString() + "</td>");

                }

                for (int j = 0; j < arrDate.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString() && dtRowDimension.Rows[i][2].ToString() == dtFactValues.Rows[k][1].ToString()
                                && dtFactValues.Rows[k][2].ToString() == arrDate[j].ToString()
                            )
                        {
                            bFound = true;
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("<td class='row_total'>");
                                //sbExcel.Append("<td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("<td>");
                                //sbExcel.Append("<td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //check to be transformed count
                            if (Convert.ToInt32(dtFactValues.Rows[k][5].ToString()) != 0)
                            {
                                sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", year, quater, ReportDataType.ToBeTransformed,adjust));
                                sb.Append(dblTemp.ToString());
                                //sbExcel.Append(dblTemp.ToString());
                                htSubTotal[j + "-1"] = Convert.ToDecimal(htSubTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                                htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                                sb.Append("</a>");
                            }
                            else
                            {
                                sb.Append("-");
                                //sbExcel.Append("-");
                            }

                            sb.Append("</a>");
                            if (arrDate[j].ToString() == "Total")
                            {
                                sb.Append("</td><td class='row_total'>");
                                //sbExcel.Append("</td><td class='row_total'>");
                            }
                            else
                            {
                                sb.Append("</td><td>");
                                //sbExcel.Append("</td><td>");
                            }

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][4].ToString());
                            //Check Delivered Count
                            if (Convert.ToInt32(dtFactValues.Rows[k][6].ToString()) != 0)
                            {
                                sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, "2", year, quater, ReportDataType.Delivered,adjust));
                                sb.Append(dblTemp.ToString());
                                //sbExcel.Append(dblTemp.ToString());
                                htSubTotal[j + "-2"] = Convert.ToDecimal(htSubTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                                htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][4].ToString());
                                sb.Append("</a>");
                            }
                            else
                            {
                                sb.Append("-");
                                //sbExcel.Append("-");
                            }
                            //sb.Append(dtFactValues.Rows[k][7].ToString());

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }
                    #region No find the value
                    if (!bFound)
                    {
                        if (arrDate[j].ToString() == "Total")
                        {
                            sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                            //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                        }
                        else
                        {
                            sb.Append("<td>-</td><td>-</td>");
                            //sbExcel.Append("<td>-</td><td>-</td>");
                        }
                    }
                    #endregion
                    #endregion


                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");

                //sbTable.Append(sb.ToString());
                //sb.Length = 0;

            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        public static string GetBlackListHTML(long employeeID, ReportType rptType, out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;

            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            //Get col dimension (CAT)
            DataTable dtColDimension = GetRowDimension(employeeID, ReportType.BlackListForCAT);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0);
            DataTable dtFactValues = dtSet.Tables[0];

            #region Get Employee Data permission ASB or Lucent

            string asbOrLucent = "";
            IEmployee employee = (IEmployee)AppContainer.Instance[Services.CONST_Employee_Service];
            asbOrLucent = employee.GetEntityPermission(employeeID);


            #endregion

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>Province</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>Province</td>";



            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region Joan 2008-10-29 array list for total link parameter-CATID
            ArrayList arrCAT = new ArrayList();
            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                    arrCAT.Add("");
                else
                    arrCAT.Add("&CATID=" + dtColDimension.Rows[i][0]);
            }

            #endregion

            #region build column head

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                {
                    sb.Append("<td colspan='2' class='row_total'>");
                    sb.Append("Total");
                }
                else
                {
                    sb.Append("<td colspan='2' class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][1].ToString());
                }
                sb.Append("</td>");
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);


            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            #region intialize subtotal for province hastable

            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {
                if (dtRowDimension.Rows[i][0] != DBNull.Value)
                {
                    htSubTotal.Add(i + "-1", 0);
                    htSubTotal.Add(i + "-2", 0);
                }
            }
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value)// && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrCAT, asbOrLucent, "", 0, 0, true);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrCAT,asbOrLucent, "",0,0, false);
                    sbTableExcel.Append(strTemp);
                    continue;
                }
                #endregion

                sb.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1] + "</td>");
                //sbExcel.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1].ToString() + "</td>");


                for (int j = 0; j < dtColDimension.Rows.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString()
                                && dtColDimension.Rows[j][0].ToString() == dtFactValues.Rows[k][1].ToString()
                            )
                        {
                            bFound = true;

                            sb.Append("<td>");
                            //sbExcel.Append("<td>");
                            //dblTemp = FormatMeTo2Digits(dtFactValues.Rows[k][2].ToString());
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][2].ToString());
                            //if (dblTemp != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[i + "-1"] = Convert.ToDecimal(htSubTotal[i + "-1"]) + dblTemp;
                            htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    sbExcel.Append("-");
                            //}

                            sb.Append("</a>");
                            sb.Append("</td><td>");
                            sbExcel.Append("</td><td>");

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //if (dblTemp != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.CEWPromised));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[i + "-2"] = Convert.ToDecimal(htSubTotal[i + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                            htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    sbExcel.Append("-");
                            //}

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }

                    #region No find the value
                    if (!bFound && dtColDimension.Rows[j][0] != DBNull.Value)
                    {
                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");
                    }

                    #endregion

                    if (dtColDimension.Rows[j][0] == DBNull.Value)
                    {
                        htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(htSubTotal[i + "-1"]);
                        htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(htSubTotal[i + "-2"]);
                    }
                    #endregion
                }

                //add sub total by province




                if (htSubTotal[i + "-1"].ToString() != "0")
                {

                    //sb.Append("<td>");
                    if (dtRowDimension.Rows[i][0] == DBNull.Value)
                    {
                        sb.Append("<td class='row_total'>" + GetLink("&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                        sb.Append("<td class='row_total'>" + GetLink("&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                    }
                    else
                    {
                        sb.Append("<td class='row_total'>" + GetLink("&ProvID=" + dtRowDimension.Rows[i][0] + "&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                        sb.Append("<td class='row_total'>" + GetLink("&ProvID=" + dtRowDimension.Rows[i][0] + "&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised) + FormatMeTo2Dgts(htSubTotal[i + "-2"].ToString()) + "</a></td>");
                    }

                    //sbExcel.Append("<td class='row_total'>" + htSubTotal[i.ToString() + "-1"].ToString() + "</td>");
                    //sbExcel.Append("<td class='row_total'>" + htSubTotal[i.ToString() + "-2"].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                    //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");




                sbTable.Append(sb.ToString());
                //sbTableExcel.Append(sbExcel.ToString());
                sbTableExcel.Append(sb.ToString());
                sb.Length = 0;
                sbExcel.Length = 0;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        //yuliang 2010-5-18
        public static string GetBlackListHTML(long employeeID, ReportType rptType, int adjust,out string err, out string excelHTML)
        {
            err = string.Empty;
            excelHTML = string.Empty;

            //Get dimension and fact talbe values
            DataTable dtRowDimension = GetRowDimension(employeeID, rptType);
            //Get col dimension (CAT)
            DataTable dtColDimension = GetRowDimension(employeeID, ReportType.BlackListForCAT);
            DataSet dtSet = GetDateDimensionAndFact(employeeID, rptType, "", 0, 0, 0, adjust);
            DataTable dtFactValues = dtSet.Tables[0];

            #region Get Employee Data permission ASB or Lucent

            string asbOrLucent = "";
            IEmployee employee = (IEmployee)AppContainer.Instance[Services.CONST_Employee_Service];
            asbOrLucent = employee.GetEntityPermission(employeeID);


            #endregion

            string tbForPage;
            string tbForExcel;

            StringBuilder sb = new StringBuilder();
            StringBuilder sbTable = new StringBuilder();
            StringBuilder sbExcel = new StringBuilder();
            StringBuilder sbTableExcel = new StringBuilder();

            tbForPage = "<table border='0'  cellpadding='2' cellspacing='1' bgcolor='black'><tr class='row_title'>";
            tbForExcel = "<table border='1'  cellpadding='2' cellspacing='0'><tr class='row_title'>";
            tbForPage += "<td rowspan='2'colspan='2'>Province</td>";
            tbForExcel += "<td rowspan='2'colspan='2'>Province</td>";



            Hashtable htSubTotal = new Hashtable(); //For save subtotal
            Hashtable htTotal = new Hashtable();    //For save total

            #region Joan 2008-10-29 array list for total link parameter-CATID
            ArrayList arrCAT = new ArrayList();
            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                    arrCAT.Add("");
                else
                    arrCAT.Add("&CATID=" + dtColDimension.Rows[i][0]);
            }

            #endregion

            #region build column head

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                {
                    sb.Append("<td colspan='2' class='row_total'>");
                    sb.Append("Total");
                }
                else
                {
                    sb.Append("<td colspan='2' class='title_month'>");
                    sb.Append(dtColDimension.Rows[i][1].ToString());
                }
                sb.Append("</td>");
                htTotal.Add(i + "-1", 0);
                htTotal.Add(i + "-2", 0);


            }
            sb.Append("</tr>");

            sb.Append("<tr class='row_title'>");

            for (int i = 0; i < dtColDimension.Rows.Count; i++)
            {
                if (dtColDimension.Rows[i][0] == DBNull.Value)
                    sb.Append("<td  class='row_total'>Count</td><td class='row_total'>Amount</td>");
                else
                    sb.Append("<td  class='title_month'>Count</td><td class='title_month'>Amount</td>");
            }
            sb.Append("</tr>");

            sbTable.Append(sb.ToString());
            sbTableExcel.Append(sb.ToString());
            #endregion

            #region intialize subtotal for province hastable

            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {
                if (dtRowDimension.Rows[i][0] != DBNull.Value)
                {
                    htSubTotal.Add(i + "-1", 0);
                    htSubTotal.Add(i + "-2", 0);
                }
            }
            #endregion

            sb.Length = 0;
            sbExcel.Length = 0;

            string strTemp = "";
            string strRptTitle = "";
            bool bFound = false;
            //double dblTemp = new double();
            decimal dblTemp = new decimal();

            #region Get Report title

            strRptTitle = GetReportTitle(rptType, "", "", "");
            tbForPage = strRptTitle + tbForPage;
            tbForExcel = strRptTitle + tbForExcel;

            #endregion


            for (int i = 0; i < dtRowDimension.Rows.Count; i++)
            {

                #region if ROLLUP line for all, output total by Month, Quater and Year

                if (dtRowDimension.Rows[i][0] == DBNull.Value)// && dtRowDimension.Rows[i][1] == DBNull.Value)
                {
                    //insert total line
                    strTemp = GetTotal(rptType, ref htTotal, arrCAT, asbOrLucent, "", 0, 0, true,adjust);
                    sbTable.Append(strTemp);
                    //strTemp = GetTotal(rptType, ref htTotal, arrCAT,asbOrLucent, "",0,0, false);
                    sbTableExcel.Append(strTemp);
                    continue;
                }
                #endregion

                sb.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1] + "</td>");
                //sbExcel.Append("<tr class='row_body'><td colspan='2'>" + dtRowDimension.Rows[i][1].ToString() + "</td>");

                for (int j = 0; j < dtColDimension.Rows.Count; j++)
                {
                    bFound = false;

                    #region find the row by row dimension and map date head

                    for (int k = 0; k < dtFactValues.Rows.Count; k++)
                    {

                        #region fine the value

                        if (dtRowDimension.Rows[i][0].ToString() == dtFactValues.Rows[k][0].ToString()
                                && dtColDimension.Rows[j][0].ToString() == dtFactValues.Rows[k][1].ToString()
                            )
                        {
                            bFound = true;

                            sb.Append("<td>");
                            //sbExcel.Append("<td>");
                            //dblTemp = FormatMeTo2Digits(dtFactValues.Rows[k][2].ToString());
                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][2].ToString());
                            //if (dblTemp != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[i + "-1"] = Convert.ToDecimal(htSubTotal[i + "-1"]) + dblTemp;
                            htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + dblTemp;
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    sbExcel.Append("-");
                            //}

                            sb.Append("</a>");
                            sb.Append("</td><td>");
                            sbExcel.Append("</td><td>");

                            dblTemp = FormatMeTo2Dgts(dtFactValues.Rows[k][3].ToString());
                            //if (dblTemp != 0)
                            //{
                            sb.Append(GetLink(dtRowDimension.Rows[i], dtFactValues.Rows[k], rptType, asbOrLucent, 0, 0, ReportDataType.CEWPromised,adjust));
                            sb.Append(dblTemp.ToString());
                            //sbExcel.Append(dblTemp.ToString());
                            htSubTotal[i + "-2"] = Convert.ToDecimal(htSubTotal[i + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                            htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(dtFactValues.Rows[k][3].ToString());
                            sb.Append("</a>");
                            //}
                            //else
                            //{
                            //    sb.Append("-");
                            //    sbExcel.Append("-");
                            //}

                            sb.Append("</td>");
                            //sbExcel.Append("</td>");


                            dtFactValues.Rows.RemoveAt(k);
                            k--;
                            break;
                        }
                        #endregion
                    }

                    #region No find the value
                    if (!bFound && dtColDimension.Rows[j][0] != DBNull.Value)
                    {
                        sb.Append("<td>-</td><td>-</td>");
                        //sbExcel.Append("<td>-</td><td>-</td>");
                    }

                    #endregion

                    if (dtColDimension.Rows[j][0] == DBNull.Value)
                    {
                        htTotal[j + "-1"] = Convert.ToDecimal(htTotal[j + "-1"]) + Convert.ToDecimal(htSubTotal[i + "-1"]);
                        htTotal[j + "-2"] = Convert.ToDecimal(htTotal[j + "-2"]) + Convert.ToDecimal(htSubTotal[i + "-2"]);
                    }
                    #endregion
                }

                //add sub total by province
                if (htSubTotal[i + "-1"].ToString() != "0")
                {

                    //sb.Append("<td>");
                    if (dtRowDimension.Rows[i][0] == DBNull.Value)
                    {
                        sb.Append("<td class='row_total'>" + GetLink("&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised,adjust) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                        sb.Append("<td class='row_total'>" + GetLink("&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised,adjust) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                    }
                    else
                    {
                        sb.Append("<td class='row_total'>" + GetLink("&ProvID=" + dtRowDimension.Rows[i][0] + "&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised,adjust) + FormatMeTo2Dgts(htSubTotal[i + "-1"].ToString()) + "</a></td>");
                        sb.Append("<td class='row_total'>" + GetLink("&ProvID=" + dtRowDimension.Rows[i][0] + "&AsbOrLucent=" + asbOrLucent, rptType, ReportDataType.CEWPromised, adjust) + FormatMeTo2Dgts(htSubTotal[i + "-2"].ToString()) + "</a></td>");
                    }

                    //sbExcel.Append("<td class='row_total'>" + htSubTotal[i.ToString() + "-1"].ToString() + "</td>");
                    //sbExcel.Append("<td class='row_total'>" + htSubTotal[i.ToString() + "-2"].ToString() + "</td>");
                }
                else
                {
                    sb.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                    //sbExcel.Append("<td class='row_total'>-</td><td class='row_total'>-</td>");
                }
                sb.Append("</tr>");
                //sbExcel.Append("</tr>");




                sbTable.Append(sb.ToString());
                //sbTableExcel.Append(sbExcel.ToString());
                sbTableExcel.Append(sb.ToString());
                sb.Length = 0;
                sbExcel.Length = 0;
            }

            tbForPage = tbForPage + sbTable + "</table>";
            tbForExcel = tbForExcel + sbTableExcel + "</table>";
            excelHTML = tbForExcel;

            return tbForPage;
        }

        #endregion

        #region private static functions

        private static bool MapValue(string strDate, object year, object quater, object month)
        {
            if (strDate == "Y" + year + "Q" + quater + "M" + month)
                return true;
            else
                return false;
        }

        private static string GetLink(DataRow drRow, ReportType reportType, int year, int contractType, string dataType, bool isSubTotal)
        {
            string dateType = "0";
            switch (dataType)
            {
                case "<1Month":
                    dateType = "0";
                    break;
                case "1-3Month":
                    dateType = "1";
                    break;
                case "3-6Month":
                    dateType = "2";
                    break;
                case "6-12Month":
                    dateType = "3";
                    break;
                case ">1Year":
                    dateType = "4";
                    break;
                case "Total":
                    dateType = "5";
                    break;
            }
            string strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + reportType;
            //if (dateType != "5")
            //{
            if (drRow != null)
            {
                switch (reportType)
                {
                    case ReportType.ByPuStatusYes:
                        if (isSubTotal && !string.IsNullOrEmpty(drRow["BGID"].ToString()))
                            strLink += "&BGID=" + drRow["BGID"];
                        else if (!string.IsNullOrEmpty(drRow["BDID"].ToString()))
                            strLink += "&BDID=" + drRow["BDID"];
                        break;
                    case ReportType.ByCatStatusYes:
                        strLink += "&CATID=" + drRow["CATID"];
                        break;
                    case ReportType.ByProvStatusYes:
                        strLink += "&ProvID=" + drRow["ProvinceID"];
                        break;
                }
            }
            //}
            strLink += "&ContractType=" + contractType;
            strLink += "&Year=" + year;
            strLink += "&DateType=" + dateType;
            strLink += "');\">";
            return strLink;
        }

        //yuliang 2010-5-28
        private static string GetLink2(DataRow drRow, ReportType reportType, int year, int adjust, string dataType, bool isSubTotal)
        {
            string dateType = "0";
            switch (dataType)
            {
                case "<1Month":
                    dateType = "0";
                    break;
                case "1-3Month":
                    dateType = "1";
                    break;
                case "3-6Month":
                    dateType = "2";
                    break;
                case "6-12Month":
                    dateType = "3";
                    break;
                case ">1Year":
                    dateType = "4";
                    break;
                case "Total":
                    dateType = "5";
                    break;
            }
            string strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + reportType;
            //if (dateType != "5")
            //{
            if (drRow != null)
            {
                switch (reportType)
                {
                    case ReportType.ByPuStatusYes:
                        if (isSubTotal && !string.IsNullOrEmpty(drRow["BGID"].ToString()))
                            strLink += "&BGID=" + drRow["BGID"];
                        else if (!string.IsNullOrEmpty(drRow["BDID"].ToString()))
                            strLink += "&BDID=" + drRow["BDID"];
                        break;
                    case ReportType.ByCatStatusYes:
                        strLink += "&CATID=" + drRow["CATID"];
                        break;
                    case ReportType.ByProvStatusYes:
                        strLink += "&ProvID=" + drRow["ProvinceID"];
                        break;
                    case ReportType.ByClusterStatusYes:
                        strLink += "&ClusterID=" + drRow["ClusterID"];
                        break;
                }
            }
            //}
            //
            //strLink += "&ContractType=" + contractType;
            if(year > 0)
                strLink += "&Year=" + year;

            strLink += "&DateType=" + dateType;

            if (adjust > 0)
                strLink += "&AdjustID=" + adjust;

            strLink += "');\">";
            return strLink;
        }

        private static string GetSubTotal(ReportType reportType, DataRow dataRow, ref Hashtable htSubTotal, int year, int contractType)
        {
            string tmp = @"<tr class='row_total'><td rowspan='3'>" + dataRow[1] + @" <br>Sub Total</td><td>金额</td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, "<1Month", true) + FormatMeTo2Dgts(htSubTotal["0-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, "1-3Month", true) + FormatMeTo2Dgts(htSubTotal["1-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, "3-6Month", true) + FormatMeTo2Dgts(htSubTotal["2-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, "6-12Month", true) + FormatMeTo2Dgts(htSubTotal["3-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, ">1Year", true) + FormatMeTo2Dgts(htSubTotal["4-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(dataRow, reportType, year, contractType, "Total", false) + FormatMeTo2Dgts(htSubTotal["5-1"].ToString()) + @"</a></td>
                            </tr>";
            if (FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) > 0)
            {
                tmp += @"<tr class='row_total'><td>%</td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "<1Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["0-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "1-3Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["1-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "3-6Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["2-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "6-12Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["3-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, ">1Year", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["4-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "Total", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                    </tr>";
            }
            else
            {
                tmp += @"<tr class='row_total'><td>%</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";
            }
            tmp += @"<tr class='row_total'><td>数量</td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "<1Month", true) + FormatMeTo2Dgts(htSubTotal["0-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "1-3Month", true) + FormatMeTo2Dgts(htSubTotal["1-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "3-6Month", true) + FormatMeTo2Dgts(htSubTotal["2-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "6-12Month", true) + FormatMeTo2Dgts(htSubTotal["3-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, ">1Year", true) + FormatMeTo2Dgts(htSubTotal["4-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(dataRow, reportType, year, contractType, "Total", false) + FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) + @"</a></td>
                    </tr>";
            htSubTotal["0-2"] = 0;
            htSubTotal["1-2"] = 0;
            htSubTotal["2-2"] = 0;
            htSubTotal["3-2"] = 0;
            htSubTotal["4-2"] = 0;
            htSubTotal["5-2"] = 0;

            htSubTotal["0-1"] = 0;
            htSubTotal["1-1"] = 0;
            htSubTotal["2-1"] = 0;
            htSubTotal["3-1"] = 0;
            htSubTotal["4-1"] = 0;
            htSubTotal["5-1"] = 0;
            return tmp;
        }

        //yu liang 2010-5-28
        private static string GetSubTotal2(ReportType reportType, DataRow dataRow, ref Hashtable htSubTotal, int year, int adjust)
        {
            string tmp = @"<tr class='row_total'><td rowspan='3'>" + dataRow[1] + @" <br>Sub Total</td><td>金额</td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, "<1Month", true) + FormatMeTo2Dgts(htSubTotal["0-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, "1-3Month", true) + FormatMeTo2Dgts(htSubTotal["1-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, "3-6Month", true) + FormatMeTo2Dgts(htSubTotal["2-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, "6-12Month", true) + FormatMeTo2Dgts(htSubTotal["3-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, ">1Year", true) + FormatMeTo2Dgts(htSubTotal["4-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(dataRow, reportType, year, adjust, "Total", false) + FormatMeTo2Dgts(htSubTotal["5-1"].ToString()) + @"</a></td>
                            </tr>";
            if (FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) > 0)
            {
                tmp += @"<tr class='row_total'><td>%</td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "<1Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["0-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "1-3Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["1-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "3-6Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["2-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "6-12Month", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["3-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, ">1Year", true) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["4-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "Total", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) /
                                       FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                    </tr>";
            }
            else
            {
                tmp += @"<tr class='row_total'><td>%</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";
            }
            tmp += @"<tr class='row_total'><td>数量</td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "<1Month", true) + FormatMeTo2Dgts(htSubTotal["0-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "1-3Month", true) + FormatMeTo2Dgts(htSubTotal["1-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "3-6Month", true) + FormatMeTo2Dgts(htSubTotal["2-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "6-12Month", true) + FormatMeTo2Dgts(htSubTotal["3-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, ">1Year", true) + FormatMeTo2Dgts(htSubTotal["4-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(dataRow, reportType, year, adjust, "Total", false) + FormatMeTo2Dgts(htSubTotal["5-2"].ToString()) + @"</a></td>
                    </tr>";
            htSubTotal["0-2"] = 0;
            htSubTotal["1-2"] = 0;
            htSubTotal["2-2"] = 0;
            htSubTotal["3-2"] = 0;
            htSubTotal["4-2"] = 0;
            htSubTotal["5-2"] = 0;

            htSubTotal["0-1"] = 0;
            htSubTotal["1-1"] = 0;
            htSubTotal["2-1"] = 0;
            htSubTotal["3-1"] = 0;
            htSubTotal["4-1"] = 0;
            htSubTotal["5-1"] = 0;
            return tmp;
        }

        private static string GetTotal(ReportType reportType, ref Hashtable htTotal, int year, int contractType)
        {
            string tmp = @"<tr class='row_total'><td rowspan='3'>总计</td><td>金额</td>
                                <td>" + GetLink(null, reportType, year, contractType, "<1Month", false) + FormatMeTo2Dgts(htTotal["0-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(null, reportType, year, contractType, "1-3Month", false) + FormatMeTo2Dgts(htTotal["1-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(null, reportType, year, contractType, "3-6Month", false) + FormatMeTo2Dgts(htTotal["2-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(null, reportType, year, contractType, "6-12Month", false) + FormatMeTo2Dgts(htTotal["3-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(null, reportType, year, contractType, ">1Year", false) + FormatMeTo2Dgts(htTotal["4-1"].ToString()) + @"</a></td>
                                <td>" + GetLink(null, reportType, year, contractType, "Total", false) + FormatMeTo2Dgts(htTotal["5-1"].ToString()) + @"</a></td>
                            </tr>";
            if (FormatMeTo2Dgts(htTotal["5-2"].ToString()) > 0)
            {
                tmp += @"<tr class='row_total'><td>%</td>
                        <td>" + GetLink(null, reportType, year, contractType, "<1Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["0-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "1-3Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["1-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "3-6Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["2-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "6-12Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["3-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, ">1Year", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["4-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "Total", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["5-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                    </tr>";
            }
            else
            {
                tmp += @"<tr class='row_total'><td>%</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";
            }
            tmp += @"<tr class='row_total'><td>数量</td>
                        <td>" + GetLink(null, reportType, year, contractType, "<1Month", false) + FormatMeTo2Dgts(htTotal["0-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "1-3Month", false) + FormatMeTo2Dgts(htTotal["1-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "3-6Month", false) + FormatMeTo2Dgts(htTotal["2-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "6-12Month", false) + FormatMeTo2Dgts(htTotal["3-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, ">1Year", false) + FormatMeTo2Dgts(htTotal["4-2"].ToString()) + @"</a></td>
                        <td>" + GetLink(null, reportType, year, contractType, "Total", false) + FormatMeTo2Dgts(htTotal["5-2"].ToString()) + @"</a></td>
                    </tr>";

            return tmp;
        }

        //yuliang 2010-5-28
        private static string GetTotal2(ReportType reportType, ref Hashtable htTotal, int year, int adjust)
        {
            string tmp = @"<tr class='row_total'><td rowspan='3'>总计</td><td>金额</td>
                                <td>" + GetLink2(null, reportType, year, adjust, "<1Month", false) + FormatMeTo2Dgts(htTotal["0-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(null, reportType, year, adjust, "1-3Month", false) + FormatMeTo2Dgts(htTotal["1-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(null, reportType, year, adjust, "3-6Month", false) + FormatMeTo2Dgts(htTotal["2-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(null, reportType, year, adjust, "6-12Month", false) + FormatMeTo2Dgts(htTotal["3-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(null, reportType, year, adjust, ">1Year", false) + FormatMeTo2Dgts(htTotal["4-1"].ToString()) + @"</a></td>
                                <td>" + GetLink2(null, reportType, year, adjust, "Total", false) + FormatMeTo2Dgts(htTotal["5-1"].ToString()) + @"</a></td>
                            </tr>";
            if (FormatMeTo2Dgts(htTotal["5-2"].ToString()) > 0)
            {
                tmp += @"<tr class='row_total'><td>%</td>
                        <td>" + GetLink2(null, reportType, year, adjust, "<1Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["0-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "1-3Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["1-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "3-6Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["2-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "6-12Month", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["3-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, ">1Year", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["4-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "Total", false) +
                       Convert.ToInt32(FormatMeTo2Dgts(htTotal["5-2"].ToString()) /
                                       FormatMeTo2Dgts(htTotal["5-2"].ToString()) * 100) +
                       @"%</a></td>
                    </tr>";
            }
            else
            {
                tmp += @"<tr class='row_total'><td>%</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>";
            }
            tmp += @"<tr class='row_total'><td>数量</td>
                        <td>" + GetLink2(null, reportType, year, adjust, "<1Month", false) + FormatMeTo2Dgts(htTotal["0-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "1-3Month", false) + FormatMeTo2Dgts(htTotal["1-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "3-6Month", false) + FormatMeTo2Dgts(htTotal["2-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "6-12Month", false) + FormatMeTo2Dgts(htTotal["3-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, ">1Year", false) + FormatMeTo2Dgts(htTotal["4-2"].ToString()) + @"</a></td>
                        <td>" + GetLink2(null, reportType, year, adjust, "Total", false) + FormatMeTo2Dgts(htTotal["5-2"].ToString()) + @"</a></td>
                    </tr>";

            return tmp;
        }


        private static string GetPercent(string count, string currentIndex, DataTable dtFactValues)
        {
            int totalCount = 0;
            string str = "-";
            foreach (DataRow dr in dtFactValues.Rows)
            {
                if (dr[0].ToString() == currentIndex && dr[1].ToString() == "Total")
                {
                    totalCount = int.Parse(dr[3].ToString());
                    break;
                }
            }
            if (totalCount > 0)
                str = Convert.ToInt32(decimal.Parse(count) / totalCount * 100).ToString();
            return str + "%";
        }

        //yuliang 2010-5-22
        private static string GetPercentForProvStatusYes(string count, string currentIndex, DataTable dtFactValues)
        {
            int totalCount = 0;
            string str = "-";
            foreach (DataRow dr in dtFactValues.Rows)
            {
                if (dr[1].ToString() == currentIndex && dr[2].ToString() == "Total")
                {
                    totalCount = int.Parse(dr[4].ToString());
                    break;
                }
            }
            if (totalCount > 0)
                str = Convert.ToInt32(decimal.Parse(count) / totalCount * 100).ToString();
            return str + "%";
        }

        private static string GetLink(string urlPara, ReportType rptType, ReportDataType rptDataType)
        {
            string strLink;
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            strLink += urlPara;
            strLink += "&DataType=" + rptDataType;

            strLink += "');\">";
            return strLink;
        }

        private static string GetLink(string urlPara, ReportType rptType, ReportDataType rptDataType,int adjust)
        {
            string strLink;
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            strLink += urlPara;
            strLink += "&DataType=" + rptDataType;

            if(adjust > 0)
                strLink += "&AdjustID=" + adjust;

            strLink += "');\">";
            return strLink;
        }

        private static string GetLink(string urlPara, ReportType rptType, DateTime? currentDate, int? contractType, string dataType)
        {
            string dateType = "0";
            switch (dataType)
            {
                case "<1Month":
                    dateType = "0";
                    break;
                case "1-3Month":
                    dateType = "1";
                    break;
                case "3-6Month":
                    dateType = "2";
                    break;
                case "6-12Month":
                    dateType = "3";
                    break;
                case ">1Year":
                    dateType = "4";
                    break;
                case "Total":
                    dateType = "5";
                    break;
            }
            string strLink = "";
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            strLink += "&CurrentDate=" + currentDate;
            strLink += "&ContractType=" + contractType;
            strLink += urlPara;
            if (dataType == "0-19%<br>Delivered" || dataType == "20-99%<br>Delivered" || dataType == "100%<br>Delivered")
                strLink += "&DeliveryType=" + dataType;
            else
                strLink += string.Format("&DateType={0}", dateType);

            strLink += "');\">";
            return strLink;
        }

        //yuliang 2010-5-26
        private static string GetLink(string urlPara, ReportType rptType, DateTime? currentDate, int? contractType, string dataType,int adjust)
        {
            string dateType = "0";
            switch (dataType)
            {
                case "<1Month":
                    dateType = "0";
                    break;
                case "1-3Month":
                    dateType = "1";
                    break;
                case "3-6Month":
                    dateType = "2";
                    break;
                case "6-12Month":
                    dateType = "3";
                    break;
                case ">1Year":
                    dateType = "4";
                    break;
                case "Total":
                    dateType = "5";
                    break;
            }
            string strLink = "";
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            strLink += "&CurrentDate=" + currentDate;
            strLink += "&ContractType=" + contractType;
            strLink += urlPara;
            if (dataType == "0-19%<br>Delivered" || dataType == "20-99%<br>Delivered" || dataType == "100%<br>Delivered")
                strLink += "&DeliveryType=" + dataType;
            else
                strLink += string.Format("&DateType={0}", dateType);

            if(adjust > 0)
                strLink += string.Format("&AdjustID={0}", adjust);

            strLink += "');\">";
            return strLink;
        }

        private static string GetLink(DataRow drRow, DataRow drCol, ReportType rptType, string asbOrLucent, int year, int quater, ReportDataType rptDataType)
        {
            return GetLink(drRow, drCol, rptType, asbOrLucent, year, quater, rptDataType, null, null);
        }

        //yuliang 2010-5-26
        private static string GetLink(DataRow drRow, DataRow drCol, ReportType rptType, string asbOrLucent, int year, int quater, ReportDataType rptDataType,int adjust)
        {
            return GetLink(drRow, drCol, rptType, asbOrLucent, year, quater, rptDataType, null, null, adjust);
        }

        private static string GetLink(DataRow drRow, DataRow drCol, ReportType rptType, string asbOrLucent, int year, int quater, ReportDataType rptDataType, DateTime? CurrentDate, int? contractType)
        {
            //Parameter year and quater is only for RiskReport
            //rptDataType: ReportDataType: Transformed, ToBeTransformed, Delivered, Or CEWPromised(for black list only)
            string dateType = "0";
            if (rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                switch (drCol["DeliveryType"].ToString())
                {
                    case "<1Month":
                        dateType = "0";
                        break;
                    case "1-3Month":
                        dateType = "1";
                        break;
                    case "3-6Month":
                        dateType = "2";
                        break;
                    case "6-12Month":
                        dateType = "3";
                        break;
                    case ">1Year":
                        dateType = "4";
                        break;
                    case "Total":
                        dateType = "5";
                        break;
                }
            }
            if (asbOrLucent == "")
                asbOrLucent = "2";

            string strLink;
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            switch (rptType)
            {
                case ReportType.BlackList:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drCol["CATID"];
                    strLink += "&AsbOrLucent=" + asbOrLucent;
                    break;
                case ReportType.DelayReport:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&DelayType=" + drCol["DelayType"];

                    break;
                case ReportType.ByProvByCATByDelivery:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&DeliveryType=" + drCol["DeliveryType"];

                    break;
                case ReportType.RiskProject:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&IsRisk=" + drCol["SecureOrRisk"];
                    strLink += "&Year=" + year;
                    strLink += "&Quater=" + quater;
                    break;
                case ReportType.ByProvStatusNo:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);
                    break;
                case ReportType.ByPuStatusNo:
                    strLink += "&BDID=" + drRow["BDID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);
                    break;
                case ReportType.ByCatStatusNo:
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);
                    break;
                case ReportType.ByProvByCATStatusNo:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);
                    break;
                case ReportType.ByProvStatusYes:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;
                case ReportType.ByPuStatusYes:
                    strLink += "&BDID=" + drRow["BDID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;
                case ReportType.ByCatStatusYes:
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;

                default:
                    {
                        switch (rptType)
                        {
                            case ReportType.ByBD_Quarterly:
                            case ReportType.ByBD:
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                            case ReportType.ByCAT_Quarterly:
                                strLink += "&CATID=" + drRow["CATID"];
                                //strLink += "&AdjustID=" + drRow["CATID"];
                                break;
                            case ReportType.ByCAT:
                                strLink += "&CATID=" + drRow["CATID"];
                                break;
                            case ReportType.ByProv_Quarterly:
                            case ReportType.ByProv:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                break;
                            case ReportType.ByProvByCAT_Quarterly:
                            case ReportType.ByProvByCAT:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&CATID=" + drRow["CATID"];
                                break;
                            case ReportType.ByProvByBD_Quarterly:
                            case ReportType.ByProvByBD:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                            case ReportType.ByCATByBD_Quarterly:
                            case ReportType.ByBDByCAT_Quarterly:
                            case ReportType.ByCATByBD:
                            case ReportType.ByBDByCAT:
                                strLink += "&CATID=" + drRow["CATID"];
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                        }
                        strLink += "&AsbOrLucent=" + asbOrLucent;
                        strLink += "&Year=" + drCol["TradeYear"];


                        if (drCol["TradeQuater"] == DBNull.Value)
                        {
                            strLink += "&Quater=";
                        }
                        else
                        {
                            strLink += "&Quater=" + drCol["TradeQuater"];
                        }
                        if (drCol["TradeMonth"] == DBNull.Value)
                        {
                            strLink += "&Month=";
                        }
                        else
                        {
                            strLink += "&Month=" + drCol["TradeMonth"];
                        }
                        break;
                    }


            }
            strLink += "&DataType=" + rptDataType;

            strLink += "');\">";
            return strLink;
        }

        //yuliang 2010-5-26
        private static string GetLink(DataRow drRow, DataRow drCol, ReportType rptType, string asbOrLucent, int year, int quater, ReportDataType rptDataType, DateTime? CurrentDate, int? contractType,int adjust)
        {
            //Parameter year and quater is only for RiskReport
            //rptDataType: ReportDataType: Transformed, ToBeTransformed, Delivered, Or CEWPromised(for black list only)
            string dateType = "0";
            if (rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                switch (drCol["DeliveryType"].ToString())
                {
                    case "<1Month":
                        dateType = "0";
                        break;
                    case "1-3Month":
                        dateType = "1";
                        break;
                    case "3-6Month":
                        dateType = "2";
                        break;
                    case "6-12Month":
                        dateType = "3";
                        break;
                    case ">1Year":
                        dateType = "4";
                        break;
                    case "Total":
                        dateType = "5";
                        break;
                }
            }
            if (asbOrLucent == "")
                asbOrLucent = "2";

            string strLink;
            strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
            strLink += "rptType=" + rptType;
            switch (rptType)
            {
                case ReportType.BlackList:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drCol["CATID"];
                    strLink += "&AsbOrLucent=" + asbOrLucent;

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.DelayReport:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&DelayType=" + drCol["DelayType"];

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.ByProvByCATByDelivery:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&DeliveryType=" + drCol["DeliveryType"];

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.RiskProject:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CATID"];
                    strLink += "&IsRisk=" + drCol["SecureOrRisk"];
                    strLink += "&Year=" + year;
                    strLink += "&Quater=" + quater;

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.ByProvStatusNo:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;

                    break;
                case ReportType.ByPuStatusNo:
                    strLink += "&BDID=" + drRow["BDID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.ByCatStatusNo:
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.ByProvByCATStatusNo:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&CurrentDate={0}", CurrentDate);
                    strLink += string.Format("&ContractType={0}", contractType);
                    if (drCol["DeliveryType"].ToString() == "0-19%<br>Delivered" || drCol["DeliveryType"].ToString() == "20-99%<br>Delivered" || drCol["DeliveryType"].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + drCol["DeliveryType"];
                    else
                        strLink += string.Format("&DateType={0}", dateType);

                    if (adjust > 0)
                        strLink += "&AdjustID=" + adjust;
                    break;
                case ReportType.ByProvStatusYes:
                    strLink += "&ProvID=" + drRow["ProvinceID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;
                case ReportType.ByPuStatusYes:
                    strLink += "&BDID=" + drRow["BDID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;
                case ReportType.ByCatStatusYes:
                    strLink += "&CATID=" + drRow["CatID"];
                    strLink += string.Format("&Year={0}", year);
                    strLink += string.Format("&ContractType={0}", contractType);
                    break;

                default:
                    {
                        switch (rptType)
                        {
                            case ReportType.ByBD_Quarterly:
                                strLink += "&BDID=" + drRow["BDID"];

                                if(adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByBD:
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                            case ReportType.ByCAT_Quarterly:
                                strLink += "&CATID=" + drRow["CATID"];

                                if (adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByCAT:
                                strLink += "&CATID=" + drRow["CATID"];
                                break;
                            case ReportType.ByProv_Quarterly:
                                strLink += "&ProvID=" + drRow["ProvinceID"];

                                if (adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByProv:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                break;
                            case ReportType.ByProvByCAT_Quarterly:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&CATID=" + drRow["CATID"];

                                if (adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByProvByCAT:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&CATID=" + drRow["CATID"];
                                break;
                            case ReportType.ByProvByBD_Quarterly:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&BDID=" + drRow["BDID"];

                                if (adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByProvByBD:
                                strLink += "&ProvID=" + drRow["ProvinceID"];
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                            case ReportType.ByCATByBD_Quarterly:
                            case ReportType.ByBDByCAT_Quarterly:
                                strLink += "&CATID=" + drRow["CATID"];
                                strLink += "&BDID=" + drRow["BDID"];

                                if (adjust > 0)
                                    strLink += "&AdjustID=" + adjust;
                                break;
                            case ReportType.ByCATByBD:
                            case ReportType.ByBDByCAT:
                                strLink += "&CATID=" + drRow["CATID"];
                                strLink += "&BDID=" + drRow["BDID"];
                                break;
                        }
                        strLink += "&AsbOrLucent=" + asbOrLucent;
                        strLink += "&Year=" + drCol["TradeYear"];


                        if (drCol["TradeQuater"] == DBNull.Value)
                        {
                            strLink += "&Quater=";
                        }
                        else
                        {
                            strLink += "&Quater=" + drCol["TradeQuater"];
                        }
                        if (drCol["TradeMonth"] == DBNull.Value)
                        {
                            strLink += "&Month=";
                        }
                        else
                        {
                            strLink += "&Month=" + drCol["TradeMonth"];
                        }
                        break;
                    }


            }
            strLink += "&DataType=" + rptDataType;

            strLink += "');\">";
            return strLink;
        }

        private static string GetSubTotal(ReportType rptType, DataRow drRow, ref Hashtable htSubTotal, ArrayList arrDate, bool withLink, DateTime currentDate, int contractType)
        {

            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";
            if (rptType == ReportType.ByPuStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    string dateType = "0";
                    switch (arrDate[j].ToString())
                    {
                        case "<1Month":
                            dateType = "0";
                            break;
                        case "1-3Month":
                            dateType = "1";
                            break;
                        case "3-6Month":
                            dateType = "2";
                            break;
                        case "6-12Month":
                            dateType = "3";
                            break;
                        case ">1Year":
                            dateType = "4";
                            break;
                        case "Total":
                            dateType = "5";
                            break;
                    }
                    string strLink = "";
                    strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                    strLink += "rptType=" + rptType;
                    strLink += "&CurrentDate=" + currentDate;
                    strLink += "&ContractType=" + contractType;
                    strLink += "&BGID=" + drRow[0];
                    if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + arrDate[j];
                    else
                        strLink += string.Format("&DateType={0}", dateType);
                    strLink += "');\">";
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            else if (rptType == ReportType.ByProvByCATStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal' colspan='2'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        string dateType = "0";
                        switch (arrDate[j].ToString())
                        {
                            case "<1Month":
                                dateType = "0";
                                break;
                            case "1-3Month":
                                dateType = "1";
                                break;
                            case "3-6Month":
                                dateType = "2";
                                break;
                            case "6-12Month":
                                dateType = "3";
                                break;
                            case ">1Year":
                                dateType = "4";
                                break;
                            case "Total":
                                dateType = "5";
                                break;
                        }
                        string strLink = "";
                        strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                        strLink += "rptType=" + rptType;
                        strLink += "&CurrentDate=" + currentDate;
                        strLink += "&ContractType=" + contractType;
                        strLink += "&ProvID=" + drRow[0];

                        if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                            strLink += "&DeliveryType=" + arrDate[j];
                        else
                            strLink += string.Format("&DateType={0}", dateType);
                        strLink += "');\">";
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            else if (rptType == ReportType.ByProvStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal' colspan='2'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        string dateType = "0";
                        switch (arrDate[j].ToString())
                        {
                            case "<1Month":
                                dateType = "0";
                                break;
                            case "1-3Month":
                                dateType = "1";
                                break;
                            case "3-6Month":
                                dateType = "2";
                                break;
                            case "6-12Month":
                                dateType = "3";
                                break;
                            case ">1Year":
                                dateType = "4";
                                break;
                            case "Total":
                                dateType = "5";
                                break;
                        }
                        string strLink = "";
                        strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                        strLink += "rptType=" + rptType;
                        strLink += "&CurrentDate=" + currentDate;
                        strLink += "&ContractType=" + contractType;
                        strLink += "&ClusterID=" + drRow[0];

                        if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                            strLink += "&DeliveryType=" + arrDate[j];
                        else
                            strLink += string.Format("&DateType={0}", dateType);
                        strLink += "');\">";
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            sbTemp.Append("</tr>");
            return sbTemp.ToString();
        }

        //yuliang 2010-5-26
        private static string GetSubTotal(ReportType rptType, DataRow drRow, ref Hashtable htSubTotal, ArrayList arrDate, bool withLink, DateTime currentDate, int contractType,int adjust)
        {

            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";
            if (rptType == ReportType.ByPuStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    string dateType = "0";
                    switch (arrDate[j].ToString())
                    {
                        case "<1Month":
                            dateType = "0";
                            break;
                        case "1-3Month":
                            dateType = "1";
                            break;
                        case "3-6Month":
                            dateType = "2";
                            break;
                        case "6-12Month":
                            dateType = "3";
                            break;
                        case ">1Year":
                            dateType = "4";
                            break;
                        case "Total":
                            dateType = "5";
                            break;
                    }
                    string strLink = "";
                    strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                    strLink += "rptType=" + rptType;
                    strLink += "&CurrentDate=" + currentDate;
                    strLink += "&ContractType=" + contractType;
                    strLink += "&BGID=" + drRow[0];
                    if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                        strLink += "&DeliveryType=" + arrDate[j];
                    else
                        strLink += string.Format("&DateType={0}", dateType);

                    if(adjust > 0)
                        strLink += "&AdjustID=" + adjust;

                    strLink += "');\">";
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            else if (rptType == ReportType.ByProvByCATStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal' colspan='2'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        string dateType = "0";
                        switch (arrDate[j].ToString())
                        {
                            case "<1Month":
                                dateType = "0";
                                break;
                            case "1-3Month":
                                dateType = "1";
                                break;
                            case "3-6Month":
                                dateType = "2";
                                break;
                            case "6-12Month":
                                dateType = "3";
                                break;
                            case ">1Year":
                                dateType = "4";
                                break;
                            case "Total":
                                dateType = "5";
                                break;
                        }
                        string strLink = "";
                        strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                        strLink += "rptType=" + rptType;
                        strLink += "&CurrentDate=" + currentDate;
                        strLink += "&ContractType=" + contractType;
                        strLink += "&ProvID=" + drRow[0];

                        if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                            strLink += "&DeliveryType=" + arrDate[j];
                        else
                            strLink += string.Format("&DateType={0}", dateType);

                        if (adjust > 0)
                            strLink += "&AdjustID=" + adjust;

                        strLink += "');\">";
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            else if (rptType == ReportType.ByProvStatusNo)
            {
                sbTemp.Append("<tr><td class='row_subtotal' colspan='2'>" + drRow[1] + " <br>Sub Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_subtotal'>");
                    dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                    if (dblTemp.ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        string dateType = "0";
                        switch (arrDate[j].ToString())
                        {
                            case "<1Month":
                                dateType = "0";
                                break;
                            case "1-3Month":
                                dateType = "1";
                                break;
                            case "3-6Month":
                                dateType = "2";
                                break;
                            case "6-12Month":
                                dateType = "3";
                                break;
                            case ">1Year":
                                dateType = "4";
                                break;
                            case "Total":
                                dateType = "5";
                                break;
                        }
                        string strLink = "";
                        strLink = "<a onclick=\"javascript:ViewDetail('ViewDetail.aspx?";
                        strLink += "rptType=" + rptType;
                        strLink += "&CurrentDate=" + currentDate;
                        strLink += "&ContractType=" + contractType;
                        strLink += "&ClusterID=" + drRow[0];

                        if (arrDate[j].ToString() == "0-19%<br>Delivered" || arrDate[j].ToString() == "20-99%<br>Delivered" || arrDate[j].ToString() == "100%<br>Delivered")
                            strLink += "&DeliveryType=" + arrDate[j];
                        else
                            strLink += string.Format("&DateType={0}", dateType);

                        if (adjust > 0)
                            strLink += "&AdjustID=" + adjust;

                        strLink += "');\">";
                        if (withLink)
                        {
                            sbTemp.Append(strLink);
                            sbTemp.Append(dblTemp.ToString());
                            sbTemp.Append("</a>");
                        }
                        else
                        {
                            sbTemp.Append(dblTemp.ToString());

                        }
                    }
                    sbTemp.Append("</td>");
                    htSubTotal[j + "-1"] = 0;
                }
            }
            sbTemp.Append("</tr>");
            return sbTemp.ToString();
        }

        private static string GetSubTotal(ReportType rptType, DataRow drRow, ref Hashtable htSubTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink)
        {
            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";

            if (asbOrLucent == "")
                asbOrLucent = "2";



            sbTemp.Append("<tr><td colspan='2' class='row_subtotal'>" + drRow[1] + " <br>Sub Total</td>");

            for (int j = 0; j < arrDate.Count; j++)
            {
                if (rptType == ReportType.DelayReport)
                {
                    #region for delay report

                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&DelayType=" + arrDate[j];

                    #endregion
                }
                else if (rptType == ReportType.ByProvByCATByDelivery)
                {
                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&DeliveryType=" + arrDate[j];
                }
                else if (rptType == ReportType.RiskProject)
                {
                    #region for risk Report

                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&IsRisk=" + arrDate[j];
                    strTemp += "&Year=" + year;
                    strTemp += "&Quater=" + quater;

                    #endregion
                }
                else
                {
                    #region from common report

                    strTemp = arrDate[j].ToString();
                    strTemp = strTemp.Replace("Y", "&Year=");
                    strTemp = strTemp.Replace("Q", "&Quater=");
                    strTemp = strTemp.Replace("M", "&Month=");
                    strTemp += "&AsbOrLucent=" + asbOrLucent;

                    switch (rptType)
                    {
                        case ReportType.ByBD:
                        case ReportType.ByBD_Quarterly:
                            strTemp += "&BGID=" + drRow[0];
                            break;
                        case ReportType.ByCATByBD:
                        case ReportType.ByCATByBD_Quarterly:
                            strTemp += "&CATID=" + drRow[0];
                            break;
                        case ReportType.ByBDByCAT:
                        case ReportType.ByBDByCAT_Quarterly:
                            strTemp += "&BDID=" + drRow[0];
                            break;
                        case ReportType.ByProvByBD:
                        case ReportType.ByProvByCAT:
                        case ReportType.ByProvByBD_Quarterly:
                        case ReportType.ByProvByCAT_Quarterly:
                            strTemp += "&ProvID=" + drRow[0];
                            break;
                    }

                    #endregion

                    #region from current year transformed

                    if (arrDate[j].ToString().IndexOf('Y' + currYear + "QM") >= 0)
                    {
                        sbTemp.Append("<td class='row_subtotal'>");
                        dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-0"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Transformed));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }
                        sbTemp.Append("</td>");
                        htSubTotal[j + "-0"] = 0;
                    }

                    #endregion
                }

                #region output subtotal value with/without link

                sbTemp.Append("<td class='row_subtotal'>");
                dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                if (dblTemp.ToString() == "0")
                    sbTemp.Append("-");
                else
                {
                    if (withLink)
                    {
                        if (rptType == ReportType.DelayReport)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                        else if (rptType == ReportType.ByProvByCATByDelivery)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                        else
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.ToBeTransformed));
                        sbTemp.Append(dblTemp.ToString());
                        sbTemp.Append("</a>");
                    }
                    else
                    {
                        sbTemp.Append(dblTemp.ToString());

                    }
                }
                sbTemp.Append("</td>");
                htSubTotal[j + "-1"] = 0;

                sbTemp.Append("<td class='row_subtotal'>");
                dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-2"].ToString());
                if (dblTemp.ToString() == "0")
                    sbTemp.Append("-");
                else
                {
                    if (withLink)
                    {
                        if (rptType == ReportType.ByProvByCATByDelivery)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                        else
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Delivered));

                        sbTemp.Append(dblTemp.ToString());
                        sbTemp.Append("</a>");

                    }
                    else
                    {
                        sbTemp.Append(dblTemp.ToString());

                    }
                }
                sbTemp.Append("</td>");
                htSubTotal[j + "-2"] = 0;

                #endregion
            }

            sbTemp.Append("</tr>");
            return sbTemp.ToString();
        }

        //yuliang 2010-5-26
        private static string GetSubTotal(ReportType rptType, DataRow drRow, ref Hashtable htSubTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink,int adjust)
        {
            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";

            if (asbOrLucent == "")
                asbOrLucent = "2";

            sbTemp.Append("<tr><td colspan='2' class='row_subtotal'>" + drRow[1] + " <br>Sub Total</td>");

            for (int j = 0; j < arrDate.Count; j++)
            {
                if (rptType == ReportType.DelayReport)
                {
                    #region for delay report

                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&DelayType=" + arrDate[j];

                    #endregion
                }
                else if (rptType == ReportType.ByProvByCATByDelivery)
                {
                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&DeliveryType=" + arrDate[j];
                }
                else if (rptType == ReportType.RiskProject)
                {
                    #region for risk Report

                    strTemp = "&AsbOrLucent=" + asbOrLucent;
                    strTemp += "&ProvID=" + drRow[0];
                    strTemp += "&IsRisk=" + arrDate[j];
                    strTemp += "&Year=" + year;
                    strTemp += "&Quater=" + quater;

                    #endregion
                }
                else
                {
                    #region from common report

                    strTemp = arrDate[j].ToString();
                    strTemp = strTemp.Replace("Y", "&Year=");
                    strTemp = strTemp.Replace("Q", "&Quater=");
                    strTemp = strTemp.Replace("M", "&Month=");
                    strTemp += "&AsbOrLucent=" + asbOrLucent;

                    switch (rptType)
                    {
                        case ReportType.ByBD:
                            strTemp += "&BGID=" + drRow[0];
                            break;
                        case ReportType.ByBD_Quarterly:
                            strTemp += "&BGID=" + drRow[0];

                            //if (adjust > 0)
                            //    strTemp += "&AdjustID=" + adjust;
                            break;
                        case ReportType.ByCATByBD:
                            strTemp += "&CATID=" + drRow[0];
                            break;
                        case ReportType.ByCATByBD_Quarterly:
                            strTemp += "&CATID=" + drRow[0];

                            //if (adjust > 0)
                            //    strTemp += "&AdjustID=" + adjust;
                            break;
                        case ReportType.ByBDByCAT:
                            strTemp += "&BDID=" + drRow[0];
                            break;
                        case ReportType.ByBDByCAT_Quarterly:
                            strTemp += "&BDID=" + drRow[0];

                            //if (adjust > 0)
                            //    strTemp += "&AdjustID=" + adjust;
                            break;
                        case ReportType.ByProvByBD:
                        case ReportType.ByProvByCAT:
                            strTemp += "&ProvID=" + drRow[0];
                            break;
                        case ReportType.ByProvByBD_Quarterly:
                        case ReportType.ByProvByCAT_Quarterly:
                            strTemp += "&ProvID=" + drRow[0];

                            //if (adjust > 0)
                            //    strTemp += "&AdjustID=" + adjust;
                            break;
                        case ReportType.ByProv_Quarterly:
                            strTemp += "&ClusterID=" + drRow[0];
                            break;
                    }

                    #endregion

                    #region from current year transformed

                    if (arrDate[j].ToString().IndexOf('Y' + currYear + "QM") >= 0)
                    {
                        sbTemp.Append("<td class='row_subtotal'>");
                        dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-0"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Transformed,adjust));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }
                        sbTemp.Append("</td>");
                        htSubTotal[j + "-0"] = 0;
                    }

                    #endregion
                }

                #region output subtotal value with/without link

                sbTemp.Append("<td class='row_subtotal'>");
                dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-1"].ToString());
                if (dblTemp.ToString() == "0")
                    sbTemp.Append("-");
                else
                {
                    if (withLink)
                    {
                        if (rptType == ReportType.DelayReport)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                        else if (rptType == ReportType.ByProvByCATByDelivery)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                        else
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.ToBeTransformed,adjust));
                        sbTemp.Append(dblTemp.ToString());
                        sbTemp.Append("</a>");
                    }
                    else
                    {
                        sbTemp.Append(dblTemp.ToString());

                    }
                }
                sbTemp.Append("</td>");
                htSubTotal[j + "-1"] = 0;

                sbTemp.Append("<td class='row_subtotal'>");
                dblTemp = FormatMeTo2Dgts(htSubTotal[j + "-2"].ToString());
                if (dblTemp.ToString() == "0")
                    sbTemp.Append("-");
                else
                {
                    if (withLink)
                    {
                        if (rptType == ReportType.ByProvByCATByDelivery)
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                        else
                            sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Delivered,adjust));

                        sbTemp.Append(dblTemp.ToString());
                        sbTemp.Append("</a>");

                    }
                    else
                    {
                        sbTemp.Append(dblTemp.ToString());

                    }
                }
                sbTemp.Append("</td>");
                htSubTotal[j + "-2"] = 0;

                #endregion
            }

            sbTemp.Append("</tr>");
            return sbTemp.ToString();
        }

        private static string GetTotal(ReportType rptType, ref Hashtable htTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink)
        {
            return GetTotal(rptType, ref  htTotal, arrDate, asbOrLucent, currYear, year, quater, withLink, null, null);
        }

        //yuliang 2010-5-26
        private static string GetTotal(ReportType rptType, ref Hashtable htTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink,int adjust)
        {
            return GetTotal(rptType, ref  htTotal, arrDate, asbOrLucent, currYear, year, quater, withLink, null, null,adjust);
        }

        private static string GetTotal(ReportType rptType, ref Hashtable htTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink, DateTime? currentDate, int? contractType)
        {
            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            int n = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";

            if (asbOrLucent == "")
                asbOrLucent = "2";
            if (rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                if (rptType == ReportType.ByProvByCATStatusNo || rptType == ReportType.ByProvStatusNo)
                    sbTemp.Append("<tr><td class='row_total' colspan='2'>Total</td>");
                else
                    sbTemp.Append("<tr><td class='row_total'>Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_total'>");
                    if (htTotal[j + "-1"].ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        if (withLink)
                        {
                            sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString()));
                            sbTemp.Append(FormatMeTo2Dgts(htTotal[j + "-1"].ToString()));
                            sbTemp.Append("</a>");
                        }
                        else
                            sbTemp.Append(htTotal[j + "-1"].ToString());
                    }
                    sbTemp.Append("</td>");
                }
                sbTemp.Append("</tr>");
                if (rptType == ReportType.ByProvByCATStatusNo || rptType == ReportType.ByProvStatusNo)
                    sbTemp.Append("<tr><td class='row_total' colspan='2'>%</td>");
                else
                    sbTemp.Append("<tr><td class='row_total'>%</td>");
                decimal total = 0M;
                for (int j = 0; j < arrDate.Count; j++)
                {
                    if (arrDate[j].ToString() == "Total")
                    {
                        total = decimal.Parse(htTotal[j + "-1"].ToString());
                    }
                }
                for (int j = 0; j < arrDate.Count; j++)
                {
                    if (arrDate[j].ToString() != "Total")
                    {
                        sbTemp.Append("<td class='row_body'>");
                        if (htTotal[j + "-1"].ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString()));
                                sbTemp.Append(Math.Round(decimal.Parse(htTotal[j + "-1"].ToString()) / total * 100));
                                sbTemp.Append("%");
                                sbTemp.Append("</a>");
                            }
                            else
                            {
                                sbTemp.Append(Math.Round(decimal.Parse(htTotal[j + "-1"].ToString()) / total * 100));
                                sbTemp.Append("%");
                            }
                        }
                    }
                    else
                    {
                        sbTemp.Append("<td class='row_body'>");
                        if (withLink)
                        {
                            sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString()));
                            sbTemp.Append("100%");
                            sbTemp.Append("</a>");
                        }
                        else
                            sbTemp.Append("100%");
                    }
                }
            }
            else
            {
                sbTemp.Append("<tr><td colspan='2' class='row_total'>Total</td>");

                if (rptType == ReportType.BlackList || rptType == ReportType.DelayReport ||
                    rptType == ReportType.ByProvByCATByDelivery)
                {
                    #region for Blacklist and DelayReport Total

                    n = (htTotal.Count / 2);
                    for (int j = 0; j < n; j++)
                    {
                        if (rptType == ReportType.BlackList)
                            strTemp = arrDate[j].ToString();
                        else if (rptType == ReportType.ByProvByCATByDelivery)
                            strTemp = "&DeliveryType=" + arrDate[j];
                        else
                            strTemp = "&DelayType=" + arrDate[j];

                        strTemp += "&AsbOrLucent=" + asbOrLucent;

                        sbTemp.Append("<td class='row_total'>");
                        if (htTotal[j + "-1"].ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                                sbTemp.Append(htTotal[j + "-1"].ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                                sbTemp.Append(htTotal[j + "-1"].ToString());
                        }

                        sbTemp.Append("</td>");

                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-2"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                                sbTemp.Append(dblTemp.ToString());
                        }

                        sbTemp.Append("</td>");
                    }
                    #endregion
                }
                else
                {
                    for (int j = 0; j < arrDate.Count; j++)
                    {

                        if (rptType == ReportType.RiskProject)
                        {
                            strTemp = "&IsRisk=" + arrDate[j];
                            strTemp += "&Year=" + year;
                            strTemp += "&Quater=" + quater;
                            strTemp += "&AsbOrLucent=" + asbOrLucent;
                        }
                        else
                        {
                            #region for common Reports

                            strTemp = arrDate[j].ToString();
                            strTemp = strTemp.Replace("Y", "&Year=");
                            strTemp = strTemp.Replace("Q", "&Quater=");
                            strTemp = strTemp.Replace("M", "&Month=");
                            strTemp += "&AsbOrLucent=" + asbOrLucent;

                            #endregion

                            #region for current year have transformed

                            if (arrDate[j].ToString().IndexOf('Y' + currYear + "QM") >= 0)
                            {

                                sbTemp.Append("<td class='row_total'>");
                                dblTemp = FormatMeTo2Dgts(htTotal[j + "-0"].ToString());
                                if (dblTemp.ToString() == "0")
                                    sbTemp.Append("-");
                                else
                                {
                                    if (withLink)
                                    {
                                        sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Transformed));
                                        sbTemp.Append(dblTemp.ToString());
                                        sbTemp.Append("</a>");
                                    }
                                    else
                                        sbTemp.Append(dblTemp.ToString());

                                }
                                sbTemp.Append("</td>");

                            }

                            #endregion
                        }

                        #region output total value with/without link

                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-1"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.ToBeTransformed));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");

                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }

                        sbTemp.Append("</td>");
                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-2"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                if (rptType != ReportType.ByProvByCATByDelivery)
                                    sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Delivered));
                                else
                                    sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");

                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }

                        sbTemp.Append("</td>");

                        #endregion
                    }

                }
            }
            sbTemp.Append("</tr>");

            return sbTemp.ToString();
        }

        //yuliang 2010-5-26
        private static string GetTotal(ReportType rptType, ref Hashtable htTotal, ArrayList arrDate, string asbOrLucent, string currYear, int year, int quater, bool withLink, DateTime? currentDate, int? contractType,int adjust)
        {
            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Length = 0;
            int n = 0;
            decimal dblTemp = 0.00M;
            string strTemp = "";

            if (asbOrLucent == "")
                asbOrLucent = "2";
            if (rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                if (rptType == ReportType.ByProvByCATStatusNo || rptType == ReportType.ByProvStatusNo)
                    sbTemp.Append("<tr><td class='row_total' colspan='2'>Total</td>");
                else
                    sbTemp.Append("<tr><td class='row_total'>Total</td>");
                for (int j = 0; j < arrDate.Count; j++)
                {
                    sbTemp.Append("<td class='row_total'>");
                    if (htTotal[j + "-1"].ToString() == "0")
                        sbTemp.Append("-");
                    else
                    {
                        if (withLink)
                        {
                            sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString(),adjust));
                            sbTemp.Append(FormatMeTo2Dgts(htTotal[j + "-1"].ToString()));
                            sbTemp.Append("</a>");
                        }
                        else
                            sbTemp.Append(htTotal[j + "-1"].ToString());
                    }
                    sbTemp.Append("</td>");
                }
                sbTemp.Append("</tr>");
                if (rptType == ReportType.ByProvByCATStatusNo || rptType == ReportType.ByProvStatusNo)
                    sbTemp.Append("<tr><td class='row_total' colspan='2'>%</td>");
                else
                    sbTemp.Append("<tr><td class='row_total'>%</td>");
                decimal total = 0M;
                for (int j = 0; j < arrDate.Count; j++)
                {
                    if (arrDate[j].ToString() == "Total")
                    {
                        total = decimal.Parse(htTotal[j + "-1"].ToString());
                    }
                }
                for (int j = 0; j < arrDate.Count; j++)
                {
                    if (arrDate[j].ToString() != "Total")
                    {
                        sbTemp.Append("<td class='row_body'>");
                        if (htTotal[j + "-1"].ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString(),adjust));
                                sbTemp.Append(Math.Round(decimal.Parse(htTotal[j + "-1"].ToString()) / total * 100));
                                sbTemp.Append("%");
                                sbTemp.Append("</a>");
                            }
                            else
                            {
                                sbTemp.Append(Math.Round(decimal.Parse(htTotal[j + "-1"].ToString()) / total * 100));
                                sbTemp.Append("%");
                            }
                        }
                    }
                    else
                    {
                        sbTemp.Append("<td class='row_body'>");
                        if (withLink)
                        {
                            sbTemp.Append(GetLink(strTemp, rptType, currentDate, contractType, arrDate[j].ToString(),adjust));
                            sbTemp.Append("100%");
                            sbTemp.Append("</a>");
                        }
                        else
                            sbTemp.Append("100%");
                    }
                }
            }
            else
            {
                sbTemp.Append("<tr><td colspan='2' class='row_total'>Total</td>");

                if (rptType == ReportType.BlackList || rptType == ReportType.DelayReport || rptType == ReportType.ByProvByCATByDelivery)
                {
                    #region for Blacklist and DelayReport Total

                    n = (htTotal.Count / 2);
                    for (int j = 0; j < n; j++)
                    {
                        if (rptType == ReportType.BlackList)
                            strTemp = arrDate[j].ToString();
                        else if (rptType == ReportType.ByProvByCATByDelivery)
                            strTemp = "&DeliveryType=" + arrDate[j];
                        else
                            strTemp = "&DelayType=" + arrDate[j];

                        strTemp += "&AsbOrLucent=" + asbOrLucent;

                        sbTemp.Append("<td class='row_total'>");
                        if (htTotal[j + "-1"].ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                                sbTemp.Append(htTotal[j + "-1"].ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                                sbTemp.Append(htTotal[j + "-1"].ToString());
                        }

                        sbTemp.Append("</td>");

                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-2"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");
                            }
                            else
                                sbTemp.Append(dblTemp.ToString());
                        }

                        sbTemp.Append("</td>");
                    }
                    #endregion
                }
                else
                {
                    for (int j = 0; j < arrDate.Count; j++)
                    {

                        if (rptType == ReportType.RiskProject)
                        {
                            strTemp = "&IsRisk=" + arrDate[j];
                            strTemp += "&Year=" + year;
                            strTemp += "&Quater=" + quater;
                            strTemp += "&AsbOrLucent=" + asbOrLucent;
                        }
                        else
                        {
                            #region for common Reports

                            strTemp = arrDate[j].ToString();
                            strTemp = strTemp.Replace("Y", "&Year=");
                            strTemp = strTemp.Replace("Q", "&Quater=");
                            strTemp = strTemp.Replace("M", "&Month=");
                            strTemp += "&AsbOrLucent=" + asbOrLucent;

                            #endregion

                            #region for current year have transformed

                            if (arrDate[j].ToString().IndexOf('Y' + currYear + "QM") >= 0)
                            {

                                sbTemp.Append("<td class='row_total'>");
                                dblTemp = FormatMeTo2Dgts(htTotal[j + "-0"].ToString());
                                if (dblTemp.ToString() == "0")
                                    sbTemp.Append("-");
                                else
                                {
                                    if (withLink)
                                    {
                                        sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Transformed,adjust));
                                        sbTemp.Append(dblTemp.ToString());
                                        sbTemp.Append("</a>");
                                    }
                                    else
                                        sbTemp.Append(dblTemp.ToString());

                                }
                                sbTemp.Append("</td>");

                            }

                            #endregion
                        }

                        #region output total value with/without link

                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-1"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.ToBeTransformed,adjust));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");

                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }

                        sbTemp.Append("</td>");
                        sbTemp.Append("<td class='row_total'>");
                        dblTemp = FormatMeTo2Dgts(htTotal[j + "-2"].ToString());
                        if (dblTemp.ToString() == "0")
                            sbTemp.Append("-");
                        else
                        {
                            if (withLink)
                            {
                                if (rptType != ReportType.ByProvByCATByDelivery)
                                    sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.Delivered,adjust));
                                else
                                    sbTemp.Append(GetLink(strTemp, rptType, ReportDataType.CEWPromised,adjust));
                                sbTemp.Append(dblTemp.ToString());
                                sbTemp.Append("</a>");

                            }
                            else
                            {
                                sbTemp.Append(dblTemp.ToString());

                            }
                        }

                        sbTemp.Append("</td>");

                        #endregion
                    }

                }
            }
            sbTemp.Append("</tr>");

            return sbTemp.ToString();
        }

        private static decimal FormatMeTo2Dgts(string strValue)
        {

            decimal dec = new decimal();
            try
            {
                dec = Convert.ToDecimal(strValue);
                dec = Math.Round(dec, 2);
                //dec = Math.Round(dec,4);//changed by yuliang 2010-5-27
            }
            catch
            {
                dec = 0.0000M;
            }

            return dec;
        }

        public static string GetReportTitle(ReportType rptType, string currYear, string lastYear, string asbOrLucent)
        {
            string strRptTitle;


            string strTemp = "";
            if (asbOrLucent == "")
                strTemp = " - All";
            else if (asbOrLucent == "0")
                strTemp = " - ASB";
            else
                strTemp = " - Lucent";


            if (rptType == ReportType.DelayReport)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Delay Report</td></tr>";
            }
            else if (rptType == ReportType.RiskProject)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Risk Project Report {0}</td></tr>";
            }

            else if (rptType == ReportType.BlackList)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Black List</td></tr>";
            }
            else if (rptType == ReportType.ByProvByCATByDelivery)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Delivered</td></tr>";
            }
            else if (rptType == ReportType.ByProvStatusNo)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract By Prov</td></tr>";
            }
            else if (rptType == ReportType.ByProvStatusYes)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Transformed  By Prov</td></tr>";
            }
            else if (rptType == ReportType.ByCatStatusNo)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract By Cat</td></tr>";
            }
            else if (rptType == ReportType.ByCatStatusYes)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Transformed By Cat</td></tr>";
            }
            else if (rptType == ReportType.ByPuStatusNo)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract By Pu</td></tr>";
            }
            else if (rptType == ReportType.ByPuStatusYes)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Transformed By Pu</td></tr>";
            }
            else if (rptType == ReportType.ByProvByCATStatusNo)
            {
                strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Delivered By Prov By Cat</td></tr>";
            }
            else
            {
                if (currYear == lastYear)
                    //strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Report " + currYear + rptType.ToString().Replace("By", " By ") + strTemp + "</td></tr>";
                    strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Report " + (rptType.ToString().Replace("By", " By ")).Replace("BD", "PU") + strTemp + "</td></tr>";
                else
                    //strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Report " + currYear + "-" + lastYear + rptType.ToString().Replace("By", " By ") + strTemp + "</td></tr>";
                    strRptTitle = "<table><tr><td colspan='6' nowrap class='report_title'>Pre-Contract Report " + (rptType.ToString().Replace("By", " By ")).Replace("BD", "PU") + strTemp + "</td></tr>";
                strRptTitle = strRptTitle.Replace("_Quarterly", "");
            }
            strRptTitle += "<tr><td colspan='3' nowrap >unit: ME 1EURO=" + GetExchangeRate() + "RMB </td>";

            if (rptType == ReportType.BlackList || rptType == ReportType.DelayReport)
            {
                strRptTitle += "<td align='right' colspan='3'nowrap >Report Date: " + DateTime.Now.ToString("yyyy-MM-dd") + "</td></tr></table>";
            }
            else
            {
                strRptTitle += "<td align='right' colspan='3' nowrap >Updated: " + GetReportDeadline() + "</td></tr></table>";
            }

            return strRptTitle;
        }

        private static DataTable GetRowDimension(long employeeID, ReportType rptType)
        {
            return GetRowDimension(employeeID, rptType, 0);
        }

        private static DataTable GetRowDimension(long employeeID, ReportType rptType, int year)
        {
            switch (rptType)
            {
                case ReportType.ByCAT_Quarterly:
                    rptType = ReportType.ByCAT;
                    break;
                case ReportType.ByBD_Quarterly:
                    rptType = ReportType.ByBD;
                    break;
                case ReportType.ByBDByCAT_Quarterly:
                    rptType = ReportType.ByBDByCAT;
                    break;
                case ReportType.ByCATByBD_Quarterly:
                    rptType = ReportType.ByCATByBD;
                    break;
                case ReportType.ByProv_Quarterly:
                    rptType = ReportType.ByProv;
                    break;
                case ReportType.ByProvByBD_Quarterly:
                    rptType = ReportType.ByProvByBD;
                    break;
                case ReportType.ByProvByCAT_Quarterly:
                    rptType = ReportType.ByProvByCAT;
                    break;
                case ReportType.ByProvByCATByDelivery:
                    rptType = ReportType.ByProvByCAT;
                    break;
                case ReportType.ByProvStatusNo:
                    rptType = ReportType.ByProvStatusNo;
                    break;
                case ReportType.ByProvStatusYes:
                    rptType = ReportType.ByProvStatusYes;
                    break;
                case ReportType.ByCatStatusNo:
                    rptType = ReportType.ByCAT;
                    break;
                case ReportType.ByCatStatusYes:
                    rptType = ReportType.ByCATALL;
                    break;
                case ReportType.ByPuStatusNo:
                    rptType = ReportType.ByBD;
                    break;
                case ReportType.ByPuStatusYes:
                    rptType = ReportType.ByBDALL;
                    break;
                case ReportType.ByProvByCATStatusNo:
                    rptType = ReportType.ByProvByCAT;
                    break;
                case ReportType.ByClusterStatusYes:
                    rptType = ReportType.ByClusterStatusYes;
                    break;

            }
            DataTable dtDimension = new DataTable();

            DataTable dtProv;
            DataTable dtCAT;
            //DataTable dtBG;
            DataTable dtBD;
            DataTable dtCluster;

            #region Get row dimension tables by permission
            IUserRole userrole = (IUserRole)AppContainer.Instance[Services.CONST_UserRole_Service];

            IProvince prov = (IProvince)AppContainer.Instance[Services.CONST_Province_Service];
            //BEGDC.PreContract.BLL.IBG bg = (BEGDC.PreContract.BLL.IBG)BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.PreContract.BLL.Services.CONST_BG_Service];
            ICAT cat = (ICAT)AppContainer.Instance[Services.CONST_CAT_Service];
            IBD bd = (IBD)AppContainer.Instance[Services.CONST_BD_Service];
            IProvinceCluster cluster = (IProvinceCluster)AppContainer.Instance[Services.CONST_ProvinceCluster_Service];

            //dtBG =bg.GetBG_DataTable("Active=1 ORDER BY SortNumber");

            if (IsAdmin(employeeID))
            {

                dtProv = prov.GetProvince_DataTable("Active=1 ORDER BY SortNumber");
                if (rptType == ReportType.ByCATALL)
                    dtCAT = cat.GetCAT_DataTable(" 1=1 ORDER BY SortNumber");
                else
                    dtCAT = cat.GetCAT_DataTable("Active=1 ORDER BY SortNumber");
                if (rptType == ReportType.ByBDALL)
                    dtBD = bd.GetBDByPermission(employeeID, true, year);
                else
                    dtBD = bd.GetBDByPermission(employeeID, true);
            }
            else
            {
                dtProv = prov.GetProvByPermission(employeeID);
                dtCAT = cat.GetCATByPermission(employeeID);
                dtBD = bd.GetBDByPermission(employeeID, false);
            }

            dtCluster = cluster.GetProvinceCluster_DataTable(" IsActive = 1 ORDER BY Sort ");
            #endregion

            #region build row dimension table
            object[] objValues = new object[4];

            string strClusterID = "";
            string strClusterCode = "";
            switch (rptType)
            {
                #region ByProvByCAT
                case ReportType.ByProvByCAT:
                case ReportType.DelayReport:
                case ReportType.RiskProject:
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");
                    dtDimension.Columns.Add("CATID");
                    dtDimension.Columns.Add("CATCode");

                    if (dtProv.Rows.Count > 0 && dtCAT.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtCAT.Rows.Count; j++)
                            {
                                objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                objValues[2] = dtCAT.Rows[j]["CATID"].ToString();
                                objValues[3] = dtCAT.Rows[j]["CATCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                            objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;

                #endregion

                #region ByProvByBD
                case ReportType.ByProvByBD:
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");

                    if (dtProv.Rows.Count > 0 && dtBD.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtBD.Rows.Count; j++)
                            {
                                objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                objValues[2] = dtBD.Rows[j]["BDID"].ToString();
                                objValues[3] = dtBD.Rows[j]["BDCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                            objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;

                    //objValues = new object[6];
                    //dtDimension.Columns.Add("ClusterID");
                    //dtDimension.Columns.Add("ClusterCode");
                    //dtDimension.Columns.Add("ProvinceID");
                    //dtDimension.Columns.Add("ProvinceEName");
                    //dtDimension.Columns.Add("BDID");
                    //dtDimension.Columns.Add("BDCode");

                    //if (dtProv.Rows.Count > 0 && dtBD.Rows.Count > 0)
                    //{
                    //    for (int i = 0; i < dtProv.Rows.Count; i++)
                    //    {
                    //        if (i == 0)
                    //        {
                    //            strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                    //            strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();
                    //        }

                    //        if (strClusterID == dtProv.Rows[i]["ClusterID"].ToString())
                    //        {
                    //            for (int j = 0; j < dtBD.Rows.Count; j++)
                    //            {
                    //                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                    //                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                    //                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                    //                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                    //                objValues[4] = dtBD.Rows[j]["BDID"].ToString();
                    //                objValues[5] = dtBD.Rows[j]["BDCode"].ToString();
                    //                dtDimension.Rows.Add(objValues);
                    //            }

                    //            objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                    //            objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                    //            objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                    //            objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                    //            objValues[4] = DBNull.Value;
                    //            objValues[5] = DBNull.Value;
                    //            dtDimension.Rows.Add(objValues);
                    //        }
                    //        else
                    //        {
                    //            objValues[0] = strClusterID;
                    //            objValues[1] = strClusterCode;
                    //            objValues[2] = DBNull.Value;
                    //            objValues[3] = DBNull.Value;
                    //            objValues[4] = DBNull.Value;
                    //            objValues[5] = DBNull.Value;
                    //            dtDimension.Rows.Add(objValues);

                    //            strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                    //            strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();

                    //            for (int j = 0; j < dtBD.Rows.Count; j++)
                    //            {
                    //                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                    //                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                    //                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                    //                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                    //                objValues[4] = dtBD.Rows[j]["BDID"].ToString();
                    //                objValues[5] = dtBD.Rows[j]["BDCode"].ToString();
                    //                dtDimension.Rows.Add(objValues);
                    //            }

                    //            objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                    //            objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                    //            objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                    //            objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                    //            objValues[4] = DBNull.Value;
                    //            objValues[5] = DBNull.Value;
                    //            dtDimension.Rows.Add(objValues);
                    //        }  
                    //    }

                    //    objValues[0] = strClusterID;
                    //    objValues[1] = strClusterCode;
                    //    objValues[2] = DBNull.Value;
                    //    objValues[3] = DBNull.Value;
                    //    objValues[4] = DBNull.Value;
                    //    objValues[5] = DBNull.Value;
                    //    dtDimension.Rows.Add(objValues);

                    //    objValues[0] = DBNull.Value;
                    //    objValues[1] = DBNull.Value;
                    //    objValues[2] = DBNull.Value;
                    //    objValues[3] = DBNull.Value;
                    //    objValues[4] = DBNull.Value;
                    //    objValues[5] = DBNull.Value;
                    //    dtDimension.Rows.Add(objValues);
                    //}
                    //break;
                #endregion

                #region ByCATByBD

                case ReportType.ByCATByBD:
                    dtDimension.Columns.Add("CATID");
                    dtDimension.Columns.Add("CATCode");
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");

                    if (dtCAT.Rows.Count > 0 && dtBD.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtCAT.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtBD.Rows.Count; j++)
                            {
                                objValues[0] = dtCAT.Rows[i]["CATID"].ToString();
                                objValues[1] = dtCAT.Rows[i]["CATCode"].ToString();
                                objValues[2] = dtBD.Rows[j]["BDID"].ToString();
                                objValues[3] = dtBD.Rows[j]["BDCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            objValues[0] = dtCAT.Rows[i]["CATID"].ToString();
                            objValues[1] = dtCAT.Rows[i]["CATCode"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                #endregion

                //Joan 2008-11-21 for new ByBDByCAT Report
                #region ByBDByCAT

                case ReportType.ByBDByCAT:
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");
                    dtDimension.Columns.Add("CATID");
                    dtDimension.Columns.Add("CATCode");


                    if (dtBD.Rows.Count > 0 && dtCAT.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtBD.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtCAT.Rows.Count; j++)
                            {
                                objValues[0] = dtBD.Rows[i]["BDID"].ToString();
                                objValues[1] = dtBD.Rows[i]["BDCode"].ToString();
                                objValues[2] = dtCAT.Rows[j]["CATID"].ToString();
                                objValues[3] = dtCAT.Rows[j]["CATCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            objValues[0] = dtBD.Rows[i]["BDID"].ToString();
                            objValues[1] = dtBD.Rows[i]["BDCode"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                #endregion

                #region ByCAT
                case ReportType.ByCAT:
                case ReportType.ByCATALL:
                case ReportType.BlackListForCAT:
                    dtDimension.Columns.Add("CATID");
                    dtDimension.Columns.Add("CATCode");
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");

                    if (dtCAT.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtCAT.Rows.Count; i++)
                        {

                            objValues[0] = dtCAT.Rows[i]["CATID"].ToString();
                            objValues[1] = dtCAT.Rows[i]["CATCode"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                #endregion

                #region ByBD --BG/BD
                case ReportType.ByBDALL:
                case ReportType.ByBD:
                    dtDimension.Columns.Add("BGID");
                    dtDimension.Columns.Add("BGCode");
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");
                    string strBGID = "";
                    string strBGCode = "";
                    if (dtBD.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtBD.Rows.Count; i++)
                        {
                            if (i == 0)
                            {
                                strBGID = dtBD.Rows[i]["BGID"].ToString();
                                strBGCode = dtBD.Rows[i]["BGCode"].ToString();
                            }

                            if (strBGID == dtBD.Rows[i]["BGID"].ToString())
                            {
                                objValues[0] = dtBD.Rows[i]["BGID"].ToString();
                                objValues[1] = dtBD.Rows[i]["BGCode"].ToString();
                                objValues[2] = dtBD.Rows[i]["BDID"].ToString();
                                objValues[3] = dtBD.Rows[i]["BDCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            else
                            {
                                objValues[0] = strBGID;
                                objValues[1] = strBGCode;
                                objValues[2] = DBNull.Value;
                                objValues[3] = DBNull.Value;
                                dtDimension.Rows.Add(objValues);

                                strBGID = dtBD.Rows[i]["BGID"].ToString();
                                strBGCode = dtBD.Rows[i]["BGCode"].ToString();

                                objValues[0] = dtBD.Rows[i]["BGID"].ToString();
                                objValues[1] = dtBD.Rows[i]["BGCode"].ToString();
                                objValues[2] = dtBD.Rows[i]["BDID"].ToString();
                                objValues[3] = dtBD.Rows[i]["BDCode"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }

                        }

                        objValues[0] = strBGID;
                        objValues[1] = strBGCode;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;

                #endregion

                #region ByProvince
                case ReportType.ByProv://added by yuliang 2010-5-18 for cluster dimension
                    dtDimension.Columns.Add("ClusterID");
                    dtDimension.Columns.Add("ClusterCode");
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");
                    
                    if (dtProv.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {
                            if (i == 0)
                            {
                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();
                            }

                            if (strClusterID == dtProv.Rows[i]["ClusterID"].ToString())
                            {
                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            else
                            {
                                objValues[0] = strClusterID;
                                objValues[1] = strClusterCode;
                                objValues[2] = DBNull.Value;
                                objValues[3] = DBNull.Value;
                                dtDimension.Rows.Add(objValues);

                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();

                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                        }

                        objValues[0] = strClusterID;
                        objValues[1] = strClusterCode;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                case ReportType.ByProvStatusNo:
                    dtDimension.Columns.Add("ClusterID");
                    dtDimension.Columns.Add("ClusterCode");
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");

                    if (dtProv.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {
                            if (i == 0)
                            {
                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();
                            }

                            if (strClusterID == dtProv.Rows[i]["ClusterID"].ToString())
                            {
                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            else
                            {
                                objValues[0] = strClusterID;
                                objValues[1] = strClusterCode;
                                objValues[2] = DBNull.Value;
                                objValues[3] = DBNull.Value;
                                dtDimension.Rows.Add(objValues);

                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();

                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                        }

                        objValues[0] = strClusterID;
                        objValues[1] = strClusterCode;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                case ReportType.ByProvStatusYes:
                    dtDimension.Columns.Add("ClusterID");
                    dtDimension.Columns.Add("ClusterCode");
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");

                    if (dtProv.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {
                            if (i == 0)
                            {
                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();
                            }

                            if (strClusterID == dtProv.Rows[i]["ClusterID"].ToString())
                            {
                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                            else
                            {
                                //objValues[0] = strClusterID;
                                //objValues[1] = strClusterCode;
                                //objValues[2] = DBNull.Value;
                                //objValues[3] = DBNull.Value;
                                //dtDimension.Rows.Add(objValues);

                                strClusterID = dtProv.Rows[i]["ClusterID"].ToString();
                                strClusterCode = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", strClusterID))[0]["ClusterCode"].ToString();

                                objValues[0] = dtProv.Rows[i]["ClusterID"].ToString();
                                objValues[1] = dtCluster.Select(String.Format(" ProvinceClusterID = {0} ", objValues[0].ToString()))[0]["ClusterCode"].ToString();
                                objValues[2] = dtProv.Rows[i]["ProvinceID"].ToString();
                                objValues[3] = dtProv.Rows[i]["ProvinceEName"].ToString();
                                dtDimension.Rows.Add(objValues);
                            }
                        }

                        //objValues[0] = strClusterID;
                        //objValues[1] = strClusterCode;
                        //objValues[2] = DBNull.Value;
                        //objValues[3] = DBNull.Value;
                        //dtDimension.Rows.Add(objValues);

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                //case ReportType.ByProvStatusYes:
                //    dtDimension.Columns.Add("ProvinceID");
                //    dtDimension.Columns.Add("ProvinceEName");
                //    dtDimension.Columns.Add("BDID");
                //    dtDimension.Columns.Add("BDCode");

                //    if (dtProv.Rows.Count > 0)
                //    {
                //        for (int i = 0; i < dtProv.Rows.Count; i++)
                //        {
                //            objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                //            objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                //            objValues[2] = DBNull.Value;
                //            objValues[3] = DBNull.Value;
                //            dtDimension.Rows.Add(objValues);
                //        }

                //        objValues[0] = DBNull.Value;
                //        objValues[1] = DBNull.Value;
                //        objValues[2] = DBNull.Value;
                //        objValues[3] = DBNull.Value;
                //        dtDimension.Rows.Add(objValues);
                //    }
                //    break;
                case ReportType.BlackList:
                    dtDimension.Columns.Add("ProvinceID");
                    dtDimension.Columns.Add("ProvinceEName");
                    dtDimension.Columns.Add("BDID");
                    dtDimension.Columns.Add("BDCode");

                    if (dtProv.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtProv.Rows.Count; i++)
                        {

                            objValues[0] = dtProv.Rows[i]["ProvinceID"].ToString();
                            objValues[1] = dtProv.Rows[i]["ProvinceEName"].ToString();
                            objValues[2] = DBNull.Value;
                            objValues[3] = DBNull.Value;
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        objValues[2] = DBNull.Value;
                        objValues[3] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                #endregion

                #region ByCluster
                case ReportType.ByClusterStatusYes:
                    objValues = new object[2];
                    dtDimension.Columns.Add("ClusterID");
                    dtDimension.Columns.Add("ClusterCode");

                    if (dtProv.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtCluster.Rows.Count; i++)
                        {
                            objValues[0] = dtCluster.Rows[i]["ProvinceClusterID"].ToString();
                            objValues[1] = dtCluster.Rows[i]["ClusterCode"].ToString();
                            dtDimension.Rows.Add(objValues);
                        }

                        objValues[0] = DBNull.Value;
                        objValues[1] = DBNull.Value;
                        dtDimension.Rows.Add(objValues);
                    }
                    break;
                #endregion

            }
            #endregion

            return dtDimension;

        }

        private static DataSet GetDateDimensionAndFact(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int year, int quater)
        {
            return GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, year, quater, null, null);
        }

        //yuliang 2010-5-18
        private static DataSet GetDateDimensionAndFact(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int year, int quater,int adjust)
        {
            return GetDateDimensionAndFact(employeeID, rptType, asbOrLucent, noOfMonth, year, quater, adjust,null, null);
        }

        private static DataSet GetDateDimensionAndFact(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int year, int quater, DateTime? currentDate, int? contractType)
        {
            DataSet dtSet = new DataSet();

            ISysRefDate sysRef = (ISysRefDate)AppContainer.Instance[Services.CONST_SysRefDate_Service];
            ISessionFactory factory = sysRef.GetSessionFactory();

            #region build stored procedure parameters
            SqlParameter[] paras = new SqlParameter[3];
            if (rptType == ReportType.RiskProject)
            {
                paras = new SqlParameter[3];
                paras[0] = new SqlParameter("@Year", SqlDbType.Int);
                paras[0].Value = year;
                paras[1] = new SqlParameter("@Quater", SqlDbType.Int);
                paras[1].Value = quater;
                paras[2] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[2].Value = employeeID;

            }
            else if (rptType == ReportType.BlackList || rptType == ReportType.DelayReport || rptType == ReportType.ByProvByCATByDelivery)
            {
                paras = new SqlParameter[1];
                paras[0] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[0].Value = employeeID;
            }
            else if (rptType == ReportType.ByCAT_Quarterly || rptType == ReportType.ByBD_Quarterly
           || rptType == ReportType.ByProv_Quarterly || rptType == ReportType.ByProvByCAT_Quarterly
           || rptType == ReportType.ByProvByBD_Quarterly || rptType == ReportType.ByCATByBD_Quarterly
           || rptType == ReportType.ByBDByCAT_Quarterly)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[0].Value = employeeID;
                paras[1] = new SqlParameter("@ASBOrLucent", SqlDbType.Char, 1);
                paras[1].Value = asbOrLucent;
            }
            else if (rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@currentDate", SqlDbType.DateTime);
                paras[0].Value = currentDate;
                paras[1] = new SqlParameter("@currentType", SqlDbType.Int);
                paras[1].Value = contractType;
            }
            else if (rptType == ReportType.ByProvStatusYes || rptType == ReportType.ByCatStatusYes || rptType == ReportType.ByPuStatusYes)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@year", SqlDbType.Int);
                paras[0].Value = year;
                paras[1] = new SqlParameter("@currentType", SqlDbType.Int);
                paras[1].Value = contractType;
            }
            else //if (rptType != ReportType.DelayReport)
            {
                paras[0] = new SqlParameter("@NoOfMonth", SqlDbType.Int);
                paras[0].Value = noOfMonth;
                paras[1] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[1].Value = employeeID;
                paras[2] = new SqlParameter("@ASBOrLucent", SqlDbType.Char, 1);
                paras[2].Value = asbOrLucent;
            }

            #endregion

            #region call stored procedure to get dataset
            using (ISession session = factory.OpenSession())
            {

                switch (rptType)
                {
                    //"UID=ecm;Password=ecm;Initial Catalog=PreContract;Data Source=135.251.32.158"
                    case ReportType.ByProvByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCAT", paras);
                        break;
                    case ReportType.ByProvByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByBD", paras);
                        break;
                    case ReportType.ByCATByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCATByBD", paras);
                        break;
                    //Joan 2008-11-21 for new ByBDByCAT report
                    case ReportType.ByBDByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBDByCAT", paras);
                        break;
                    case ReportType.ByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCAT", paras);
                        break;
                    case ReportType.ByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBD", paras);
                        break;

                    case ReportType.ByProv:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvince", paras);
                        break;
                    case ReportType.ByProvByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCAT_Quarterly", paras);
                        break;
                    case ReportType.ByProvByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByBD_Quarterly", paras);
                        break;
                    case ReportType.ByCATByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCATByBD_Quarterly", paras);
                        break;
                    //Joan 2008-11-21 for new ByBDByCAT report
                    case ReportType.ByBDByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBDByCAT_Quarterly", paras);
                        break;
                    case ReportType.ByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCAT_Quarterly", paras);
                        break;
                    case ReportType.ByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBD_Quarterly", paras);
                        break;

                    case ReportType.ByProv_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvince_Quarterly", paras);
                        break;
                    case ReportType.DelayReport:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetDelayReport", paras);
                        break;
                    case ReportType.RiskProject:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetRiskProjectReport", paras);
                        break;
                    case ReportType.BlackList:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetBlackListReport", paras);
                        break;
                    case ReportType.ByProvByCATByDelivery:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCATByDeliveryDate", paras);
                        break;
                    case ReportType.ByProvStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvStatusNo", paras);
                        break;
                    case ReportType.ByCatStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCatStatusNo", paras);
                        break;
                    case ReportType.ByPuStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByPuStatusNo", paras);
                        break;
                    case ReportType.ByProvStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvStatusYes", paras);
                        break;
                    case ReportType.ByCatStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCatStatusYes", paras);
                        break;
                    case ReportType.ByPuStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByPuStatusYes", paras);
                        break;
                    case ReportType.ByProvByCATStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCatStatusNo", paras);
                        break;
                }
            }
            return dtSet;
            #endregion
        }

        //yuliang 2010-5-18
        private static DataSet GetDateDimensionAndFact(long employeeID, ReportType rptType, string asbOrLucent, int noOfMonth, int year, int quater, int adjust,DateTime? currentDate, int? contractType)
        {
            DataSet dtSet = new DataSet();

            ISysRefDate sysRef = (ISysRefDate)AppContainer.Instance[Services.CONST_SysRefDate_Service];
            ISessionFactory factory = sysRef.GetSessionFactory();

            #region build stored procedure parameters
            SqlParameter[] paras = new SqlParameter[3];
            if (rptType == ReportType.RiskProject)
            {
                paras = new SqlParameter[4];
                paras[0] = new SqlParameter("@Year", SqlDbType.Int);
                paras[0].Value = year;
                paras[1] = new SqlParameter("@Quater", SqlDbType.Int);
                paras[1].Value = quater;
                paras[2] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[2].Value = employeeID;
                paras[3] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[3].Value = adjust;
            }
            else if (rptType == ReportType.BlackList || rptType == ReportType.DelayReport || rptType == ReportType.ByProvByCATByDelivery)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[0].Value = employeeID;
                paras[1] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[1].Value = adjust;
            }
            else if (rptType == ReportType.ByCAT_Quarterly || rptType == ReportType.ByBD_Quarterly
           || rptType == ReportType.ByProv_Quarterly || rptType == ReportType.ByProvByCAT_Quarterly
           || rptType == ReportType.ByProvByBD_Quarterly || rptType == ReportType.ByCATByBD_Quarterly
           || rptType == ReportType.ByBDByCAT_Quarterly)
            {
                paras = new SqlParameter[3];
                paras[0] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[0].Value = employeeID;
                paras[1] = new SqlParameter("@ASBOrLucent", SqlDbType.Char, 1);
                paras[1].Value = asbOrLucent;
                paras[2] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[2].Value = adjust;
            }
            else if (rptType == ReportType.ByProvStatusNo || rptType == ReportType.ByCatStatusNo || rptType == ReportType.ByPuStatusNo || rptType == ReportType.ByProvByCATStatusNo)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@currentDate", SqlDbType.DateTime);
                paras[0].Value = currentDate;
                //paras[1] = new SqlParameter("@currentType", SqlDbType.Int);
                //paras[1].Value = contractType;
                paras[1] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[1].Value = adjust;
            }
            else if (rptType == ReportType.ByProvStatusYes || rptType == ReportType.ByCatStatusYes || rptType == ReportType.ByPuStatusYes || rptType == ReportType.ByClusterStatusYes)
            {
                paras = new SqlParameter[2];
                paras[0] = new SqlParameter("@year", SqlDbType.Int);
                paras[0].Value = year;
                //paras[1] = new SqlParameter("@currentType", SqlDbType.Int);
                //paras[1].Value = contractType;
                paras[1] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[1].Value = adjust;
            }
            else //if (rptType != ReportType.DelayReport)
            {
                paras = new SqlParameter[4];
                paras[0] = new SqlParameter("@NoOfMonth", SqlDbType.Int);
                paras[0].Value = noOfMonth;
                paras[1] = new SqlParameter("@EmployeeID", SqlDbType.Int);
                paras[1].Value = employeeID;
                paras[2] = new SqlParameter("@ASBOrLucent", SqlDbType.Char, 1);
                paras[2].Value = asbOrLucent;
                paras[3] = new SqlParameter("@Adjust", SqlDbType.Int);
                paras[3].Value = adjust;
            }

            #endregion

            #region call stored procedure to get dataset
            using (ISession session = factory.OpenSession())
            {

                switch (rptType)
                {
                    //"UID=ecm;Password=ecm;Initial Catalog=PreContract;Data Source=135.251.32.158"
                    case ReportType.ByProvByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCAT2", paras);//sp_GetReportByProvByCAT changed to sp_GetReportByProvByCAT2 yuliang 2010-5-18
                        break;
                    case ReportType.ByProvByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByBD2", paras);//sp_GetReportByProvByBD changed to sp_GetReportByProvByBD2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCATByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCATByBD2", paras);//sp_GetReportByCATByBD changed to sp_GetReportByCATByBD2 yuliang 2010-5-18
                        break;
                    //Joan 2008-11-21 for new ByBDByCAT report
                    case ReportType.ByBDByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBDByCAT2", paras);//sp_GetReportByBDByCAT changed to sp_GetReportByBDByCAT2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCAT:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCAT2", paras);//sp_GetReportByCAT changed to sp_GetReportByCAT2 yuliang 2010-5-18
                        break;
                    case ReportType.ByBD:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBD2", paras);//sp_GetReportByBD changed to sp_GetReportByBD2 yuliang 2010-5-18
                        break;

                    case ReportType.ByProv:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvince2", paras);//sp_GetReportByProvince changed to sp_GetReportByProvince2 yuliang 2010-5-18
                        break;
                    case ReportType.ByProvByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCAT_Quarterly2", paras);//sp_GetReportByProvByCAT_Quarterly changed to sp_GetReportByProvByCAT_Quarterly2 yuliang 2010-5-18
                        break;
                    case ReportType.ByProvByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByBD_Quarterly2", paras);//sp_GetReportByProvByBD_Quarterly changed to sp_GetReportByProvByBD_Quarterly2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCATByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCATByBD_Quarterly2", paras);//sp_GetReportByCATByBD_Quarterly changed to sp_GetReportByCATByBD_Quarterly2 yuliang 2010-5-18
                        break;
                    //Joan 2008-11-21 for new ByBDByCAT report
                    case ReportType.ByBDByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBDByCAT_Quarterly2", paras);//sp_GetReportByBDByCAT_Quarterly changed to sp_GetReportByBDByCAT_Quarterly2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCAT_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCAT_Quarterly2", paras);//sp_GetReportByCAT_Quarterly changed to sp_GetReportByCAT_Quarterly2 yuliang 2010-5-18
                        break;
                    case ReportType.ByBD_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByBD_Quarterly2", paras);//sp_GetReportByBD_Quarterly changed to sp_GetReportByBD_Quarterly2 yuliang 2010-5-18
                        break;

                    case ReportType.ByProv_Quarterly:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvince_Quarterly2", paras);//sp_GetReportByProvince_Quarterly changed to sp_GetReportByProvince_Quarterly2 yuliang 2010-5-18
                        break;
                    case ReportType.DelayReport:
                        if(adjust > 0)
                            dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetDelayReport2", paras);//sp_GetDelayReport changed to sp_GetDelayReport2 yuliang 2010-5-18
                        else
                            dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetDelayReport", paras);
                        break;
                    case ReportType.RiskProject:
                        if(adjust > 0)
                            dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetRiskProjectReport2", paras);//sp_GetRiskProjectReport changed to sp_GetRiskProjectReport2 yuliang 2010-5-18
                        else
                            dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetRiskProjectReport", paras);
                        break;
                    case ReportType.BlackList:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetBlackListReport2", paras);//sp_GetBlackListReport changed to sp_GetBlackListReport2 yuliang 2010-5-18
                        break;
                    case ReportType.ByProvByCATByDelivery:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCATByDeliveryDate2", paras);//sp_GetReportByProvByCATByDeliveryDate changed to sp_GetReportByProvByCATByDeliveryDate2 yuliang 2010-5-18
                        break;
                    case ReportType.ByProvStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvStatusNo2", paras);//sp_GetReportByProvStatusNo changed to sp_GetReportByProvStatusNo2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCatStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCatStatusNo2", paras);//sp_GetReportByCatStatusNo changed to sp_GetReportByCatStatusNo2 yuliang 2010-5-28
                        break;
                    case ReportType.ByPuStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByPuStatusNo2", paras);//sp_GetReportByPuStatusNo changed to sp_GetReportByPuStatusNo2 yuliang 2010-5-28
                        break;
                    case ReportType.ByProvStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvStatusYes2", paras);//sp_GetReportByProvStatusYes changed to sp_GetReportByProvStatusYes2 yuliang 2010-5-18
                        break;
                    case ReportType.ByCatStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByCatStatusYes2", paras);//sp_GetReportByCatStatusYes changed to sp_GetReportByCatStatusYes2 yuliang 2010-5-28
                        break;
                    case ReportType.ByPuStatusYes:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByPuStatusYes2", paras); //sp_GetReportByPuStatusYes changed to sp_GetReportByPuStatusYes2 yuliang 2010-5-28
                        break;
                    case ReportType.ByProvByCATStatusNo:
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByProvByCatStatusNo2", paras);//sp_GetReportByProvByCatStatusNo changed to sp_GetReportByProvByCatStatusNo2 yuliang 2010-5-28
                        break;
                    case ReportType.ByClusterStatusYes://added by yuliang 2010-5-23
                        dtSet = SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection,
                             "sp_GetReportByClusterStatusYes", paras);
                        break;
                }
            }
            return dtSet;
            #endregion
        }

        #endregion

    }
}
